1 | #ifndef _IRC_CLIENT_FUNC |
---|
2 | #define _IRC_CLIENT_FUNC |
---|
3 | |
---|
4 | std::string GetUser(std::string szU) |
---|
5 | { |
---|
6 | int pos = szU.find("!"); |
---|
7 | return szU.substr(0, pos); |
---|
8 | } |
---|
9 | // Delink will remove anything considered "non chat" from a string |
---|
10 | // Linked items (items that players can click on to see a description) |
---|
11 | // contain extra characters wich the client filter out, this function |
---|
12 | // makes sure people on irc do not see those characters. |
---|
13 | std::string Delink(std::string msg) |
---|
14 | { |
---|
15 | std::size_t pos; |
---|
16 | while((pos = msg.find("|Hitem")) != std::string::npos) |
---|
17 | { |
---|
18 | std::size_t find1 = msg.find("|h", pos); |
---|
19 | std::size_t find2 = msg.find("|h", find1 + 2); |
---|
20 | msg.replace(pos, find1 - pos + 2, "\x2"); |
---|
21 | msg.replace(msg.find("|h", pos), 2, "\x2"); |
---|
22 | } |
---|
23 | while((pos = msg.find("|Henchant")) != std::string::npos) |
---|
24 | { |
---|
25 | std::size_t find1 = msg.find("|h", pos); |
---|
26 | std::size_t find2 = msg.find("|h", find1 + 2); |
---|
27 | msg.replace(pos, find1 - pos + 2, "\x2"); |
---|
28 | msg.replace(msg.find("|h", pos), 2, "\x2"); |
---|
29 | //msg.replace(find2, 2, "\x2"); |
---|
30 | } |
---|
31 | return msg; |
---|
32 | } |
---|
33 | |
---|
34 | // This function converts the characters used by the client to identify colour to IRC format. |
---|
35 | std::string WoWcol2IRC(std::string msg) |
---|
36 | { |
---|
37 | std::size_t pos; |
---|
38 | char IRCCol[9][4] = { "\xF", "\xF", "\x3\x31\x34", "\x3\x30\x33", "\x3\x31\x32", "\x3\x30\x36", "\x3\x30\x37", "\x3\x30\x34", "\x3\x30\x37"}; |
---|
39 | char WoWCol[9][12] = { "|r", "|cffffffff", "|cff9d9d9d", "|cff1eff00", "|cff0070dd", "|cffa335ee", "|cffff8000", "|cffe6cc80", "|cffffd000"}; |
---|
40 | for (int i=0; i<=8; i++) |
---|
41 | { |
---|
42 | while ((pos = msg.find(WoWCol[i])) != std::string::npos) |
---|
43 | { |
---|
44 | if (i == 0) |
---|
45 | msg.replace(pos, 2, IRCCol[i]); |
---|
46 | else |
---|
47 | msg.replace(pos, 10, IRCCol[i]); |
---|
48 | } |
---|
49 | } |
---|
50 | return msg; |
---|
51 | } |
---|
52 | |
---|
53 | // This function converts the characters used by IRC to identify colour to a format the client can understand. |
---|
54 | std::string IRCcol2WoW(std::string msg) |
---|
55 | { |
---|
56 | std::size_t pos; |
---|
57 | char IRCCol[16][4] = { "\x3\x30", "\x3\x31", "\x3\x32", "\x3\x33", "\x3\x34", "\x3\x35", "\x3\x36", "\x3\x37", "\x3\x38", "\x3\x39", "\x3\x31\x30", "\x3\x31\x31", "\x3\x31\x32", "\x3\x31\x33", "\x3\x31\x34", "\x3\x31\x35"}; |
---|
58 | char IRCCol2[10][4] = { "\x3\x30\x30", "\x3\x30\x31", "\x3\x30\x32", "\x3\x30\x33", "\x3\x30\x34", "\x3\x30\x35", "\x3\x30\x36", "\x3\x30\x37", "\x3\x30\x38", "\x3\x30\x39"}; |
---|
59 | char WoWcol[16][12] = { "|cffffffff", "|cff000000", "|cff00007f", "|cff009300", "|cffff0000", "|cff7f0000", "|cff9c009c", "|cfffc9300", "|cffffff00", "|cff00fc00", "|cff009393", "|cff00ffff", "|cff0000fc", "|cffff00ff", "|cff7f7f7f", "|cffd2d2d2"}; |
---|
60 | for (int i=15; i>=0; i--) |
---|
61 | { |
---|
62 | if (i<10) |
---|
63 | { |
---|
64 | while ((pos = msg.find(IRCCol2[i])) != std::string::npos) |
---|
65 | { |
---|
66 | msg.replace(pos, 3, WoWcol[i]); |
---|
67 | } |
---|
68 | while ((pos = msg.find(IRCCol[i])) != std::string::npos) |
---|
69 | { |
---|
70 | msg.replace(pos, 2, WoWcol[i]); |
---|
71 | } |
---|
72 | |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | while ((pos = msg.find(IRCCol[i])) != std::string::npos) |
---|
77 | { |
---|
78 | msg.replace(pos, 3, WoWcol[i]); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | // Remove Bold, Reverse, Underline from IRC |
---|
83 | char Checker[3][3] = {"\x2","\x16","\x1F"}; // This is the Hex part not Dec. In Decimal its (2,22,31) |
---|
84 | for(int I=0; I < 3; I++) |
---|
85 | { |
---|
86 | while ((pos = msg.find(Checker[I])) != std::string::npos) |
---|
87 | { |
---|
88 | msg.replace(pos, 1, ""); |
---|
89 | } |
---|
90 | } |
---|
91 | // Finished Removing ! |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | while ((pos = msg.find("\x3")) != std::string::npos) |
---|
96 | { |
---|
97 | msg.replace(pos, 1, "|r"); |
---|
98 | } |
---|
99 | while ((pos = msg.find("\xF")) != std::string::npos) |
---|
100 | { |
---|
101 | msg.replace(pos, 1, "|r"); |
---|
102 | } |
---|
103 | |
---|
104 | return msg; |
---|
105 | } |
---|
106 | |
---|
107 | // This function compares 2 strings |
---|
108 | int nocase_cmp(const string & s1, const string& s2) |
---|
109 | { |
---|
110 | string::const_iterator it1=s1.begin(); |
---|
111 | string::const_iterator it2=s2.begin(); |
---|
112 | |
---|
113 | //stop when either string's end has been reached |
---|
114 | while ( (it1!=s1.end()) && (it2!=s2.end()) ) |
---|
115 | { |
---|
116 | if(::toupper(*it1) != ::toupper(*it2)) //letters differ? |
---|
117 | // return -1 to indicate smaller than, 1 otherwise |
---|
118 | return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; |
---|
119 | //proceed to the next character in each string |
---|
120 | ++it1; |
---|
121 | ++it2; |
---|
122 | } |
---|
123 | size_t size1=s1.size(), size2=s2.size(); // cache lengths |
---|
124 | //return -1,0 or 1 according to strings' lengths |
---|
125 | if (size1==size2) |
---|
126 | return 0; |
---|
127 | return (size1<size2) ? -1 : 1; |
---|
128 | } |
---|
129 | |
---|
130 | std::string MakeMsgA(const char *sLine, ... ) |
---|
131 | { |
---|
132 | va_list ap; |
---|
133 | char tmpoutp[1024]; |
---|
134 | va_start(ap, sLine); |
---|
135 | vsnprintf(tmpoutp, 1024, sLine, ap ); |
---|
136 | va_end(ap); |
---|
137 | std::string outp = tmpoutp; |
---|
138 | return outp; |
---|
139 | } |
---|
140 | |
---|
141 | std::string MakeMsgP(int CLINE, std::string Msg, Player *plr) |
---|
142 | { |
---|
143 | // std::string ChatTag = ""; |
---|
144 | // switch (plr->GetTeam()) |
---|
145 | // { |
---|
146 | // case 67:ChatTag.append("4");break; //horde |
---|
147 | // case 469:ChatTag.append("12");break; //alliance |
---|
148 | // } |
---|
149 | std::string sMsg = sIRC.MakeMsg(sIRC.GetChatLine(CLINE), "$Msg", Msg); |
---|
150 | // sMsg = ChatTag + MakeMsg(sMsg, "$Name", plr->GetName()); |
---|
151 | if (plr->GetTeam() == 67) |
---|
152 | sMsg = sIRC.MakeMsg(sMsg, "$Name", MakeMsgA("\0034%s\003", plr->GetName())); |
---|
153 | else if (plr->GetTeam() == 469) |
---|
154 | sMsg = sIRC.MakeMsg(sMsg, "$Name", MakeMsgA("\00312%s\003", plr->GetName())); |
---|
155 | if(plr->isAFK()) |
---|
156 | sMsg = sIRC.MakeMsg(sMsg, "$Tag", "<AFK>"); |
---|
157 | else if(plr->isDND()) |
---|
158 | sMsg = sIRC.MakeMsg(sMsg, "$Tag", "<DND>"); |
---|
159 | else |
---|
160 | sMsg = sIRC.MakeMsg(sMsg, "$Tag", ""); |
---|
161 | sMsg = sIRC.MakeMsg(sMsg, "$Level", MakeMsgA("%d", plr->getLevel())); |
---|
162 | sMsg = Delink(sMsg); |
---|
163 | sMsg = WoWcol2IRC(sMsg); |
---|
164 | return sMsg; |
---|
165 | } |
---|
166 | |
---|
167 | /* |
---|
168 | std::string MakeMsg(std::string msg, std::string var, int val) |
---|
169 | { |
---|
170 | std::ostringstream ss; |
---|
171 | ss << val; |
---|
172 | |
---|
173 | std::string nval = ss.str(); |
---|
174 | std::size_t start = msg.find(var); |
---|
175 | if (start != std::string::npos) |
---|
176 | msg.replace(start, var.length(), val); |
---|
177 | return msg; |
---|
178 | } |
---|
179 | */ |
---|
180 | /* |
---|
181 | std::string MakeMsg(const char *sLine, ... ) |
---|
182 | { |
---|
183 | va_list ap; |
---|
184 | char tmpoutp[1024]; |
---|
185 | va_start(ap, sLine); |
---|
186 | vsnprintf(tmpoutp, 1024, sLine, ap ); |
---|
187 | va_end(ap); |
---|
188 | std::string outp = tmpoutp; |
---|
189 | return outp; |
---|
190 | } |
---|
191 | */ |
---|
192 | |
---|
193 | // This function checks if a channel exists in out configuration |
---|
194 | // Mangchat supports as many channels as you like |
---|
195 | // However the default has been set to 10 |
---|
196 | // if you wish to increase this you must edit the: |
---|
197 | // MAX_CONF_CHANNELS variable in IRCClient.h |
---|
198 | bool Channel_Valid(std::string Channel) |
---|
199 | { |
---|
200 | for(int i=1;i < sIRC._chan_count + 1;i++) |
---|
201 | { |
---|
202 | if(nocase_cmp(sIRC._wow_chan[i], Channel)==0) |
---|
203 | return true; |
---|
204 | } |
---|
205 | return false; |
---|
206 | } |
---|
207 | |
---|
208 | std::string GetWoWChannel(std::string Channel) |
---|
209 | { |
---|
210 | for(int i=1;i < sIRC._chan_count + 1;i++) |
---|
211 | { |
---|
212 | if("#" + sIRC._irc_chan[i] == Channel) |
---|
213 | return sIRC._wow_chan[i]; |
---|
214 | } |
---|
215 | return ""; |
---|
216 | } |
---|
217 | |
---|
218 | std::string GetIRCChannel(std::string Channel) |
---|
219 | { |
---|
220 | for(int i=1;i < sIRC._chan_count + 1;i++) |
---|
221 | { |
---|
222 | if(sIRC._wow_chan[i] == Channel) |
---|
223 | return sIRC._irc_chan[i]; |
---|
224 | } |
---|
225 | return ""; |
---|
226 | } |
---|
227 | |
---|
228 | std::string* getArray(std::string PARAMS, int nCount, std::string ) |
---|
229 | { |
---|
230 | std::string *array = new std::string[nCount]; |
---|
231 | if(PARAMS.size() > 0) |
---|
232 | { |
---|
233 | int pcnt = 0; |
---|
234 | size_t ps = 0; |
---|
235 | size_t pc = -1; |
---|
236 | for(int i = 0;i < nCount;i++) |
---|
237 | { |
---|
238 | pc = PARAMS.find(" ", pc + 1); |
---|
239 | if(i + 1 == nCount && nCount != 1) |
---|
240 | { |
---|
241 | if(ps > 0 && pc > 0) |
---|
242 | array[i] = PARAMS.substr(ps, PARAMS.size() - ps); |
---|
243 | } |
---|
244 | else |
---|
245 | array[i] = PARAMS.substr(ps, pc - ps); |
---|
246 | ps = pc + 1; |
---|
247 | } |
---|
248 | } |
---|
249 | return array; |
---|
250 | } |
---|
251 | #endif |
---|