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