login._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2006 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: login.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 #include <macros.h>
20 class login {
21 public:
22 
23 
24 
25 
26  object oUser;
27  string sClientClass;
28  int iClientFeatures;
29 
30 /**
31  * Get the connected user object of this socket.
32  *
33  * @return the user object
34  */
35 object get_user_object()
36 {
37  return oUser;
38 }
39 
40 /**
41  * return the object id of this object - the id of the connected user
42  *
43  * @return the object id
44  */
45 final object get_object_id()
46 {
47  if ( objectp(oUser) )
48  return oUser->get_object_id();
49  else
50  return 0;
51 }
52 
53 /**
54  * Get the object class of the connected user object.
55  *
56  * @return the users object class (CLASS_USER)
57  */
58 final int get_object_class()
59 {
60  if ( objectp(oUser) )
61  return oUser->get_object_class();
62  else
63  return 0;
64 }
65 
66 /**
67  * Get the client description of this socket.
68  *
69  * @return client description of the socket.
70  */
71 string get_client_class()
72 {
73  return sClientClass;
74 }
75 
76 /**
77  * Check if a given object is the user object of this connection.
78  *
79  * @param object obj - object to check if its oUser
80  * @return true or false
81  * @see
82  */
83 protected:
84 final bool
85 is_user_object(object obj)
86 {
87  if ( !objectp(obj) || !objectp(oUser) )
88  return false;
89  if ( obj->get_object_id() == oUser->get_object_id() )
90  return true;
91  return false;
92 }
93 
94 public:
95 
96 /**
97  * Connect this socket object with an user object.
98  *
99  * @param object uid - the user to connect to
100  * @return the last login of the user
101  */
102 protected:
103  int login_user(object uid)
104 {
105  if ( objectp(oUser) ) {
106  // disconnect other user first
107  oUser->disconnect();
108  }
109  oUser = uid;
110  return oUser->connect(this_object());
111 }
112 
113 public:
114 
115 protected:
116  void logout_user()
117 {
118  if ( objectp(oUser) )
119  oUser->disconnect();
120 }
121 
122 public:
123 
124 
125 /**
126  * Get the client features of the connection set upon login.
127  *
128  * @return client features described in client.h
129  */
130 int get_client_features()
131 {
132  return iClientFeatures;
133 }
134 
135 int get_status()
136 {
137  return iClientFeatures;
138 }
139 
140 string get_identifier()
141 {
142  if ( objectp(oUser) )
143  return oUser->get_identifier();
144  return "unknown";
145 }
146 
147 string describe()
148 {
149  return "~" + (objectp(oUser) ? oUser->get_identifier(): "anonymous");
150 }
151 
152 
153 };