]> jfr.im git - irc/gameservirc.git/blob - gameserv/aClient.cpp
9de597ff608f475be66fc9920a64a6241680be02
[irc/gameservirc.git] / gameserv / aClient.cpp
1 #include "aClient.h"
2 #include "options.h"
3 #include "extern.h"
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 aClient::aClient(char *n)
8 {
9 #ifdef DEBUGMODE
10 log("aClient created: %s", (n[0] == '\0' ? "NULL" : n));
11 #endif
12 strcpy(nick, n);
13
14 #ifdef P10
15 strcpy(realnick, n);
16 #endif
17
18 stats = NULL;
19 flags = 0;
20 }
21 #ifdef P10
22 aClient::aClient(char *n, char *rn)
23 {
24 #ifdef DEBUGMODE
25 log("aClient created: %s", (n[0] == '\0' ? "NULL" : n));
26 #endif
27 strcpy(nick, n);
28 strcpy(realnick, rn);
29 stats = NULL;
30 flags = 0;
31 }
32 #endif
33
34 aClient::aClient(const aClient &right)
35 {
36 #ifdef DEBUGMODE
37 log("aClient created from another aClient: %s\n", right.nick);
38 #endif
39
40 stats = NULL;
41 flags = 0;
42 setData(&right);
43 }
44
45 aClient::aClient()
46 {
47 aClient("");
48 }
49
50 aClient::~aClient()
51 {
52 if (stats)
53 {
54 #ifdef DEBUGMODE
55 log("aClient deleted: %s %s %s", nick, stats->getName().c_str(),
56 stats->getPassword().c_str());
57 #endif
58
59 delete stats;
60 }
61 #ifdef DEBUGMODE
62 else
63 {
64 log("aClient deleted: %s", nick);
65 }
66 #endif
67
68 flags = 0;
69 }
70
71 bool aClient::operator!=(const aClient &right)
72 {
73 return !(*this == right);
74 }
75
76 bool aClient::operator==(const aClient &right)
77 {
78 if (strcmp(nick, right.nick) == 0 && stats == right.stats)
79 {
80 return true;
81 }
82 else
83 {
84 return false;
85 }
86 }
87
88 ostream &operator<<( ostream &out, const aClient &c )
89 {
90 out << (c.nick[0] == '\0' ? "NULL" : c.nick);
91 return out;
92 }
93
94 void aClient::setData(const aClient *right)
95 {
96 if (right != this)
97 {
98 strcpy(nick, right->nick);
99 #ifdef P10
100 strcpy(realnick, right->realnick);
101 #endif
102 if (right->stats)
103 {
104 if (!stats)
105 stats = new Player;
106 #ifdef DEBUGMODE
107 log("Should be setting data for %s", right->stats->getName().c_str());
108 #endif
109
110 stats->setData(right->stats);
111 }
112 }
113 }
114
115 long int aClient::setFlags(long int newflags)
116 {
117 flags = newflags;
118 return getFlags();
119 }
120
121 long int aClient::addFlag(long int flag)
122 {
123 flags |= flag;
124 return getFlags();
125 }
126
127 long int aClient::remFlag(long int flag)
128 {
129 flags &= ~flag;
130 return getFlags();
131 }