1 | #ifndef _IRC_CLIENT_H |
---|
2 | #define _IRC_CLIENT_H |
---|
3 | |
---|
4 | #include "Policies/Singleton.h" |
---|
5 | #include "Player.h" |
---|
6 | #include "IRCLog.h" |
---|
7 | #include "IRCCmd.h" |
---|
8 | |
---|
9 | using namespace std; |
---|
10 | // The maximum ammount of channels used |
---|
11 | // in the channel array you can have as much channels as you |
---|
12 | // want, but it is important to always have at least equal or more |
---|
13 | // channels then you specify in your mangosd.conf |
---|
14 | #define MAX_CONF_CHANNELS 10 |
---|
15 | #define MAX_CHAT_LINES 10 |
---|
16 | // time we need to wait before we try another connecton attempt |
---|
17 | // Default is 30 seconds |
---|
18 | #define MAX_SCRIPT_INST 10 |
---|
19 | // CLINES is used for the default chatlines |
---|
20 | // By using the GetChatLine function its easier and faster |
---|
21 | // to receieve the line you need. |
---|
22 | enum CLINES |
---|
23 | { |
---|
24 | IRC_WOW = 0, |
---|
25 | WOW_IRC = 1, |
---|
26 | JOIN_WOW = 2, |
---|
27 | JOIN_IRC = 3, |
---|
28 | LEAVE_WOW = 4, |
---|
29 | LEAVE_IRC = 5, |
---|
30 | CHANGE_NICK = 6 |
---|
31 | }; // Chatlines |
---|
32 | // CACTION is used by the Handle_WoW_Channel function |
---|
33 | // this function is called in channel.h when a player |
---|
34 | // joins or leave a channel inside the client. |
---|
35 | enum CACTION |
---|
36 | { |
---|
37 | CHANNEL_JOIN, |
---|
38 | CHANNEL_LEAVE, |
---|
39 | }; |
---|
40 | |
---|
41 | enum script_Names |
---|
42 | { |
---|
43 | MCS_Players_Online = 0, |
---|
44 | }; |
---|
45 | |
---|
46 | // IRCClient main class |
---|
47 | class IRCClient : public ZThread::Runnable |
---|
48 | { |
---|
49 | public: |
---|
50 | // IRCClient Constructor |
---|
51 | IRCClient(); |
---|
52 | // IRCClient Destructor |
---|
53 | ~IRCClient(); |
---|
54 | // ZThread Entry |
---|
55 | void run(); |
---|
56 | public: |
---|
57 | // AH Function |
---|
58 | void AHFunc(uint64 itmid, std::string itmnme, std::string plname, uint32 faction); |
---|
59 | // IRCClient active |
---|
60 | bool Active; |
---|
61 | // Connected to IRC |
---|
62 | bool Connected; |
---|
63 | // Socket indentifier |
---|
64 | int SOCKET; |
---|
65 | fd_set sfdset; |
---|
66 | // Send data to IRC, in addition the endline is added \n |
---|
67 | bool SendIRC(std::string data); |
---|
68 | // This function is called in ChatHandler.cpp and processes the chat from game to IRC |
---|
69 | void Send_WoW_IRC(Player *plr, std::string Channel, std::string Msg); |
---|
70 | // Sends a message to all players on the specified channel |
---|
71 | void Send_WoW_Channel(const char *channel, std::string chat); |
---|
72 | // Send a system message to all players |
---|
73 | void Send_WoW_System(std::string Message); |
---|
74 | // Send a message to the specified IRC channel |
---|
75 | void Send_IRC_Channel(std::string sChannel, std::string sMsg, bool NoPrefix = false, std::string nType = "PRIVMSG"); |
---|
76 | // Sends a message to all IRC Channels |
---|
77 | void Send_IRC_Channels(std::string sMsg); |
---|
78 | std::string MakeMsg(std::string msg, std::string var, std::string val) |
---|
79 | { |
---|
80 | std::size_t start = msg.find(var); |
---|
81 | if (start != std::string::npos) |
---|
82 | msg.replace(start, var.length(), val); |
---|
83 | return msg; |
---|
84 | } |
---|
85 | void Send_WoW_Player(string sPlayer, string sMsg); |
---|
86 | void Send_WoW_Player(Player *plr, string sMsg); |
---|
87 | |
---|
88 | // This function is called in Channel.cpp and processes Join/leave messages |
---|
89 | void Handle_WoW_Channel(std::string Channel, Player *plr, int nAction); |
---|
90 | void ResetIRC(); |
---|
91 | public: |
---|
92 | void AutoJoinChannel(Player *plr); |
---|
93 | |
---|
94 | public: |
---|
95 | bool Script_Lock[5]; |
---|
96 | bool _AmiOp; |
---|
97 | |
---|
98 | public: |
---|
99 | string _Mver; |
---|
100 | // IRC Server host |
---|
101 | string _Host; |
---|
102 | // IRC Server Port |
---|
103 | int _Port; |
---|
104 | // IRC Username |
---|
105 | string _User; |
---|
106 | // IRC Password |
---|
107 | string _Pass; |
---|
108 | // IRC Nickname |
---|
109 | string _Nick; |
---|
110 | // Authentication type |
---|
111 | int _Auth; |
---|
112 | string _Auth_Nick; |
---|
113 | // IRC Connect code |
---|
114 | string _ICC; |
---|
115 | // IRC Default channel |
---|
116 | string _defchan; |
---|
117 | // IRC Leave Default channel |
---|
118 | int _ldefc; |
---|
119 | // Wait Connect Time |
---|
120 | int _wct; |
---|
121 | // BotMask Options |
---|
122 | int Botmask; |
---|
123 | // Status Channel |
---|
124 | int Status; |
---|
125 | // Announce Channel |
---|
126 | int anchn; |
---|
127 | int autoanc; |
---|
128 | // IRC Channel count |
---|
129 | int _chan_count; |
---|
130 | // IRC Channel list |
---|
131 | // Array to store our IRC channels |
---|
132 | // each element will corrospond |
---|
133 | // with _wow_chan array below. |
---|
134 | std::string _irc_chan[MAX_CONF_CHANNELS]; |
---|
135 | // Game Channel list |
---|
136 | std::string _wow_chan[MAX_CONF_CHANNELS]; |
---|
137 | // AutoJoin Options |
---|
138 | int ajoin; |
---|
139 | string ajchan; |
---|
140 | // Online Command Max Results |
---|
141 | int onlrslt; |
---|
142 | // Channel OnJoin/Restart/Kick Messages |
---|
143 | string JoinMsg; |
---|
144 | string RstMsg; |
---|
145 | string kikmsg; |
---|
146 | // Misc Options |
---|
147 | string ojGM1; |
---|
148 | string ojGM2; |
---|
149 | string ojGM3; |
---|
150 | string ojGM4; |
---|
151 | string ojGM5; |
---|
152 | string logfile; |
---|
153 | int games; |
---|
154 | int gmlog; |
---|
155 | // IRC Commands Security Level |
---|
156 | int CACCT; |
---|
157 | int CBAN; |
---|
158 | int CCHAN; |
---|
159 | int CCHAR; |
---|
160 | int CFUN; |
---|
161 | int CHELP; |
---|
162 | int CINCHAN; |
---|
163 | int CINFO; |
---|
164 | int CITEM; |
---|
165 | int CJAIL; |
---|
166 | int CKICK; |
---|
167 | int _KILL; |
---|
168 | int CLEVEL; |
---|
169 | int CLOOKUP; |
---|
170 | int CMONEY; |
---|
171 | int CMUTE; |
---|
172 | int CONLINE; |
---|
173 | int CPM; |
---|
174 | int CRESTART; |
---|
175 | int CREVIVE; |
---|
176 | int CSAVEALL; |
---|
177 | int CSHUTDOWN; |
---|
178 | int CSPELL; |
---|
179 | int CSYSMSG; |
---|
180 | int CTELE; |
---|
181 | int CTOP; |
---|
182 | int CWHO; |
---|
183 | // BotMask |
---|
184 | int BOTMASK; |
---|
185 | // Max connect attempt |
---|
186 | int _MCA; |
---|
187 | // Auto rejoin when kicked from irc |
---|
188 | int _autojoinkick; |
---|
189 | // IRC Command prefix |
---|
190 | string _cmd_prefx; |
---|
191 | int _op_gm; |
---|
192 | int _op_gm_lev; |
---|
193 | // Array that contains our chatlines from the conf file |
---|
194 | // To increase this value change the MAX_CHAT_LINE define above |
---|
195 | // Make sure the number of elements must match your items |
---|
196 | // (remeber this starts at 0 so 0..9 is 10 items) |
---|
197 | // and that you load the line in the LoadConfig function. |
---|
198 | string ILINES[MAX_CHAT_LINES]; |
---|
199 | string GetChatLine(int nItem); |
---|
200 | |
---|
201 | int _Max_Script_Inst; |
---|
202 | // MAX_SCRIPT_INST |
---|
203 | |
---|
204 | IRCLog iLog; |
---|
205 | |
---|
206 | public: |
---|
207 | // Load MangChat configuration file |
---|
208 | bool LoadConfig(char const* cfgfile); |
---|
209 | void SetCfg(char const* cfgfile); |
---|
210 | char const* CfgFile; |
---|
211 | |
---|
212 | private: |
---|
213 | // Returns default chatline based on enum CLINES |
---|
214 | // Initialize socket library |
---|
215 | bool InitSock(); |
---|
216 | // Connect to IRC Server |
---|
217 | bool Connect(const char *cHost, int nPort); |
---|
218 | // Login to IRC Server |
---|
219 | bool Login(std::string sNick, std::string sUser, std::string sPass); |
---|
220 | // Send raw data to IRC |
---|
221 | bool SendData(const char *data); |
---|
222 | // Disconnect from IRC and cleanup socket |
---|
223 | void Disconnect(); |
---|
224 | // Processes the data receieved from IRC |
---|
225 | void Handle_IRC(std::string sData); |
---|
226 | // Receieves data from the socket. |
---|
227 | void SockRecv(); |
---|
228 | }; |
---|
229 | #endif |
---|
230 | #define sIRC MaNGOS::Singleton<IRCClient>::Instance() |
---|