]>
Commit | Line | Data |
---|---|---|
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->name, stats->password); | |
56 | #endif | |
57 | ||
58 | delete stats; | |
59 | } | |
60 | #ifdef DEBUGMODE | |
61 | else | |
62 | { | |
63 | log("aClient deleted: %s", nick); | |
64 | } | |
65 | #endif | |
66 | ||
67 | flags = 0; | |
68 | } | |
69 | ||
70 | ostream &operator<<( ostream &out, const aClient &c ) | |
71 | { | |
72 | out << (c.nick[0] == '\0' ? "NULL" : c.nick); | |
73 | return out; | |
74 | } | |
75 | ||
76 | void aClient::setData(const aClient *right) | |
77 | { | |
78 | if (right != this) | |
79 | { | |
80 | strcpy(nick, right->nick); | |
81 | #ifdef P10 | |
82 | strcpy(realnick, right->realnick); | |
83 | #endif | |
84 | if (right->stats) | |
85 | { | |
86 | if (!stats) | |
87 | stats = new Player; | |
88 | #ifdef DEBUGMODE | |
89 | log("Should be setting data for %s", right->stats->name); | |
90 | #endif | |
91 | ||
92 | stats->setData(right->stats); | |
93 | } | |
94 | } | |
95 | } | |
96 | ||
97 | long int aClient::setFlags(long int newflags) | |
98 | { | |
99 | flags = newflags; | |
100 | return getFlags(); | |
101 | } | |
102 | ||
103 | long int aClient::addFlag(long int flag) | |
104 | { | |
105 | flags |= flag; | |
106 | return getFlags(); | |
107 | } | |
108 | ||
109 | long int aClient::remFlag(long int flag) | |
110 | { | |
111 | flags &= ~flag; | |
112 | return getFlags(); | |
113 | } |