vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Guild Event Manager by Kiki of European Cho'gall (Alliance) |
||
3 | Communication module (parse/send) |
||
4 | |||
5 | Chaque message envoyé est de la forme : |
||
6 | <GEM_CMD>-<Stamp>-<EventID>[GEM_TOKEN<Param>]* |
||
7 | - GEM_CMD : Entier -- Type de paquet |
||
8 | - Stamp : Entier -- Stamp de l'emetteur au moment de l'envoi du message, relatif au leader de l'event EventID |
||
9 | - EventID : String -- EventID de l'event (identifiant unique) |
||
10 | - Param : <Variable> -- Parametres associés au type de paquet |
||
11 | |||
12 | Events : |
||
13 | ------ |
||
14 | - Update/Create Event : <Leader> <Date> <Place> <Comment> <Max> <Levels> <Class Limits> <Titulars> <Substitutes> <Replacements> |
||
15 | - Close Event : Nothing |
||
16 | |||
17 | |||
18 | Commands : |
||
19 | -------- |
||
20 | Each command has at least the following fields : |
||
21 | - event leader |
||
22 | - event date |
||
23 | - ACK type (0 or 1) |
||
24 | - player affected |
||
25 | - player from |
||
26 | |||
27 | [P] Permanent command (stored) |
||
28 | [V] Volative command (not stored) |
||
29 | Leader commands : |
||
30 | - [P] TITULAR : <player name> -- Informs player he is in titular list |
||
31 | - [P] SUBSTITUTE : <player name> -- Informs player he is in substitute list |
||
32 | - [P] REPLACEMENT : <player name> -- Informs player he is in replacement list |
||
33 | - [P] KICK : <player name> [Reason] -- Informs player he has been kicked from event |
||
34 | - [P] BAN : <player name> [Reason] -- Informs player he has been banned from event |
||
35 | - [P] UNBAN : <player name> -- Informs player he has been unbanned from event |
||
36 | - [V] LEADER : <player name> <Events data> -- Informs player he is now the new leader |
||
37 | - [V] INFOS : <player level> <player guild> <player zone> -- Give informations about me |
||
38 | |||
39 | Non-leader commands : |
||
40 | - [P] SUBSCRIBE : <sub> [Comment] -- Subscribe to an event -- <sub>(1/0) informs the leader if you want to be put directly in substitute queue (so he will invite you only if he don't find someone to replace you) |
||
41 | - [P] UNSUBSCRIBE : [Comment] -- Unsubscribe from an event |
||
42 | ]] |
||
43 | |||
44 | |||
45 | --------------- Shared variables --------------- |
||
46 | GEM_GLOBAL_CMD = "GlobalEventId1"; -- special ev_id tag for global commands |
||
47 | GEM_CMD_EVENT_UPDATE = "01"; -- Event updated (or created) |
||
48 | GEM_CMD_EVENT_CLOSE = "02"; -- Event closed |
||
49 | GEM_CMD_CMD_SUBSCRIBE = "03"; -- Subscribe : <Class> <Guild> <Level> <Sub> <Comment> |
||
50 | GEM_CMD_CMD_UNSUBSCRIBE = "04"; -- Unsubscribe : <Comment> |
||
51 | GEM_CMD_CMD_TITULAR = "05"; -- Titular |
||
52 | GEM_CMD_CMD_SUBSTITUTE = "06"; -- Substitute |
||
53 | GEM_CMD_CMD_REPLACEMENT = "07"; -- Replacement |
||
54 | GEM_CMD_CMD_KICK = "08"; -- Kick |
||
55 | GEM_CMD_CMD_BAN = "09"; -- Ban |
||
56 | GEM_CMD_CMD_UNBAN = "10"; -- UnBan |
||
57 | GEM_CMD_EVENT_LEADER = "11"; -- New event leader |
||
58 | GEM_CMD_PLAYER_INFOS = "12"; -- New infos about myself |
||
59 | GEM_CMD_CMD_ASSISTANT = "13"; -- Add assistant |
||
60 | |||
61 | -- GUI notify values |
||
62 | GEM_NOTIFY_NEW_EVENT = 1; |
||
63 | GEM_NOTIFY_CLOSE_EVENT = 2; |
||
64 | GEM_NOTIFY_EVENT_UPDATE = 3; |
||
65 | GEM_NOTIFY_SUBSCRIBER = 4; |
||
66 | GEM_NOTIFY_UNSUBSCRIBER = 5; |
||
67 | GEM_NOTIFY_MY_SUBSCRIPTION = 6; |
||
68 | GEM_NOTIFY_PLAYER_INFOS = 7; |
||
69 | |||
70 | -- Other variables |
||
71 | GEM_COM_Channels = nil; |
||
72 | GEM_COM_LastJoinerTime = 0; |
||
73 | |||
74 | --------------- Local variables --------------- |
||
75 | |||
76 | --local _GEM_TOKEN = '\35'; -- Debug value |
||
77 | --local _GEM_TOKEN_SUB_TOKEN = '\38'; -- Debug value |
||
78 | --local _GEM_TOKEN_EMPTY = '\36'; -- Debug value |
||
79 | --local _GEM_TOKEN_MORE = '\33'; -- Debug value |
||
80 | local _GEM_TOKEN = '\30'; |
||
81 | local _GEM_TOKEN_SUB_TOKEN = '\29'; |
||
82 | local _GEM_TOKEN_EMPTY = '\28'; |
||
83 | local _GEM_TOKEN_MORE = '\27'; |
||
84 | local _GEM_PARSE_PATTERN = "([^".._GEM_TOKEN.."]+)"; |
||
85 | local _GEM_PARSE_PATTERN_SUB_PATTERN = "([^".._GEM_TOKEN_SUB_TOKEN.."]+)"; |
||
86 | local _GEM_NotifyCallBackFunction = nil; |
||
87 | local _GEM_IntToClass = { ["1"] = "WARRIOR"; ["2"] = "PALADIN"; ["3"] = "SHAMAN"; ["4"] = "ROGUE"; ["5"] = "MAGE"; ["6"] = "WARLOCK"; ["7"] = "HUNTER"; ["8"] = "DRUID"; ["9"] = "PRIEST" }; |
||
88 | local _GEM_ClassToInt = { ["WARRIOR"] = "1"; ["PALADIN"] = "2"; ["SHAMAN"] = "3"; ["ROGUE"] = "4"; ["MAGE"] = "5"; ["WARLOCK"] = "6"; ["HUNTER"] = "7"; ["DRUID"] = "8"; ["PRIEST"] = "9" }; |
||
89 | local _GEMComm_ScheduledUpdates = {}; |
||
90 | local _GEMComm_Dispatch = {}; |
||
91 | local _GEM_MoreCounter = 1; |
||
92 | local _GEMComm_MultiplePackets = {}; |
||
93 | local _GEM_COM_QueuedMessages = {}; |
||
94 | local _GEM_COM_RoutineScheduled = false; |
||
95 | local _GEM_COM_LastPlayerInfosSend = 0; |
||
96 | |||
97 | -- Consts |
||
98 | local _GEM_MAX_STRING_LENGTH = 240; |
||
99 | local _GEM_PIPE_ENTITIE = "\127p"; |
||
100 | local _GEM_COM_MaxSendPerSchedule = 1; |
||
101 | local _GEM_COM_ScheduledTaskInterval = 1.500; |
||
102 | local _GEM_COM_PlayersInfosInterval = 5*60; -- 5 min |
||
103 | |||
104 | --------------- Internal functions --------------- |
||
105 | |||
106 | local function _GEM_COM_NameFromAlias(alias) |
||
107 | for name,chantab in GEM_COM_Channels |
||
108 | do |
||
109 | if(chantab.aliasSet and chantab.aliasSet == alias) |
||
110 | then |
||
111 | return chantab.id; |
||
112 | end |
||
113 | end |
||
114 | return nil; |
||
115 | end |
||
116 | |||
117 | _GEM_COM_oldSendChatMessage = SendChatMessage; |
||
118 | local function _GEM_COM_newSendChatMessage(msg,sys,lang,name) |
||
119 | local id = _GEM_COM_NameFromAlias(sys); |
||
120 | if(id) |
||
121 | then |
||
122 | return _GEM_COM_oldSendChatMessage(string.gsub(msg,"|",_GEM_PIPE_ENTITIE),"CHANNEL",lang,id); |
||
123 | end |
||
124 | return _GEM_COM_oldSendChatMessage(msg,sys,lang,name); |
||
125 | end |
||
126 | SendChatMessage = _GEM_COM_newSendChatMessage; |
||
127 | |||
128 | local function _GEM_COM_ScheduledPlayerInfos() |
||
129 | if(_GEM_COM_LastPlayerInfosSend + _GEM_COM_PlayersInfosInterval < time()) |
||
130 | then |
||
131 | GEM_ChatDebug(GEM_DEBUG_GLOBAL,"_GEM_COM_ScheduledPlayerInfos : Too long since last player infos send."); |
||
132 | GEM_COM_PlayerInfos(); |
||
133 | end |
||
134 | |||
135 | -- Reschedule routine |
||
136 | GEMSystem_Schedule(10,_GEM_COM_ScheduledPlayerInfos); |
||
137 | end |
||
138 | |||
139 | local function _GEM_COM_ScheduledSendRoutine() |
||
140 | local msg_sent = 0; |
||
141 | |||
142 | while(table.getn(_GEM_COM_QueuedMessages) > 0 and not GEM_YouAreDrunk) |
||
143 | do |
||
144 | local channel = _GEM_COM_QueuedMessages[1].channel; |
||
145 | local cmd = _GEM_COM_QueuedMessages[1].cmd; |
||
146 | local ev_id = _GEM_COM_QueuedMessages[1].ev_id; |
||
147 | local stamp = _GEM_COM_QueuedMessages[1].stamp; |
||
148 | local msgstring = _GEM_COM_QueuedMessages[1].msgstring; |
||
149 | |||
150 | while(GEM_COM_Channels[channel] == nil) |
||
151 | do |
||
152 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"_GEM_COM_ScheduledSendRoutine : GEM_COM_Channels["..tostring(channel).."] is nil (left channel ?). Discarding message !"); |
||
153 | table.remove(_GEM_COM_QueuedMessages,1); |
||
154 | if(table.getn(_GEM_COM_QueuedMessages) == 0) |
||
155 | then |
||
156 | break; |
||
157 | end |
||
158 | -- Re-read params |
||
159 | local channel = _GEM_COM_QueuedMessages[1].channel; |
||
160 | local cmd = _GEM_COM_QueuedMessages[1].cmd; |
||
161 | local ev_id = _GEM_COM_QueuedMessages[1].ev_id; |
||
162 | local stamp = _GEM_COM_QueuedMessages[1].stamp; |
||
163 | local msgstring = _GEM_COM_QueuedMessages[1].msgstring; |
||
164 | end |
||
165 | |||
166 | if(GEM_COM_Channels[channel].id == 0) -- Channel not init ! |
||
167 | then |
||
168 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"_GEM_COM_ScheduledSendRoutine : ChannelID = "..tostring(GEM_COM_Channels[channel].id).." for "..tostring(channel)); |
||
169 | GEM_InitChannels(false); |
||
170 | if(GEM_COM_Channels[channel].id == 0) -- Still not joined ? |
||
171 | then |
||
172 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"_GEM_COM_ScheduledSendRoutine : Channel '"..tostring(channel).."' still not init, rescheduling send later"); |
||
173 | break; |
||
174 | end |
||
175 | end |
||
176 | -- DEBUG |
||
177 | if(GEM_Events.debug == 1) |
||
178 | then |
||
179 | if(GetChannelName(channel) ~= GEM_COM_Channels[channel].id) |
||
180 | then |
||
181 | if(GetChannelName(channel) ~= 0) |
||
182 | then |
||
183 | GEM_ChatWarning("_GEM_COM_ScheduledSendRoutine : CurrentChanID differs from saved one : "..GetChannelName(channel).." - "..GEM_COM_Channels[channel].id); |
||
184 | else |
||
185 | GEM_ChatWarning("_GEM_COM_ScheduledSendRoutine : If you've left GEM's channel by hand, ignore this message, otherwise please contact Kiki"); |
||
186 | end |
||
187 | table.remove(_GEM_COM_QueuedMessages,1); |
||
188 | break; |
||
189 | end |
||
190 | end |
||
191 | -- END DEBUG |
||
192 | |||
193 | if(cmd == GEM_CMD_EVENT_UPDATE) -- Special case, we must set the real stamp when sending (we specified the offset) |
||
194 | then |
||
195 | stamp = time() - stamp; |
||
196 | end |
||
197 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_ScheduledSendRoutine : Sending command "..cmd.." for EventID "..ev_id.." on Channel "..channel); |
||
198 | local prefix = "<GEM"..GEM_MAJOR.."."..GEM_MINOR..">"..cmd.."-"..stamp.."-"..ev_id; |
||
199 | local msg = prefix..msgstring; |
||
200 | |||
201 | while(string.len(msg) > _GEM_MAX_STRING_LENGTH) |
||
202 | do |
||
203 | local submsg = string.sub(msg,1,_GEM_MAX_STRING_LENGTH); |
||
204 | if(string.sub(submsg,string.len(submsg)) == _GEM_TOKEN) |
||
205 | then |
||
206 | submsg = submsg.._GEM_TOKEN_EMPTY; |
||
207 | end |
||
208 | submsg = submsg.._GEM_TOKEN.._GEM_TOKEN_MORE.._GEM_MoreCounter; |
||
209 | local addmsg = string.sub(msg,_GEM_MAX_STRING_LENGTH+1); |
||
210 | if(string.sub(addmsg,1,1) == _GEM_TOKEN) |
||
211 | then |
||
212 | addmsg = _GEM_TOKEN_EMPTY..addmsg; |
||
213 | end |
||
214 | msg = prefix.._GEM_TOKEN_MORE.._GEM_MoreCounter.."-"..addmsg; |
||
215 | _GEM_COM_newSendChatMessage(submsg,"CHANNEL",nil,GEM_COM_Channels[channel].id); |
||
216 | msg_sent = msg_sent + 1; |
||
217 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_ScheduledSendRoutine : Splitted command, MoreCounter is ".._GEM_MoreCounter.." : "..submsg); |
||
218 | end |
||
219 | _GEM_MoreCounter = _GEM_MoreCounter + 1; |
||
220 | _GEM_COM_newSendChatMessage(msg,"CHANNEL",nil,GEM_COM_Channels[channel].id); |
||
221 | msg_sent = msg_sent + 1; |
||
222 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_ScheduledSendRoutine : Sending last msg part : "..msg); |
||
223 | |||
224 | table.remove(_GEM_COM_QueuedMessages,1); |
||
225 | if(msg_sent >= _GEM_COM_MaxSendPerSchedule) |
||
226 | then |
||
227 | break; |
||
228 | end |
||
229 | end |
||
230 | |||
231 | -- Reschedule routine |
||
232 | GEMSystem_Schedule(_GEM_COM_ScheduledTaskInterval,_GEM_COM_ScheduledSendRoutine); |
||
233 | end |
||
234 | |||
235 | local function _GEM_COM_QueueMessage(channel,cmd,ev_id,stamp,msgstring) |
||
236 | -- Queue the message |
||
237 | table.insert(_GEM_COM_QueuedMessages, { channel=channel, cmd=cmd, ev_id=ev_id, stamp=stamp, msgstring=msgstring }); |
||
238 | end |
||
239 | |||
240 | local function _GEM_COM_UnpackClasses(clas) |
||
241 | local classes = {}; |
||
242 | if(clas and clas ~= "") |
||
243 | then |
||
244 | for c in string.gfind(clas,_GEM_PARSE_PATTERN_SUB_PATTERN) |
||
245 | do |
||
246 | if(c ~= "") |
||
247 | then |
||
248 | local _,_,id,mini,maxi,tit,sub,repl = string.find(c,"(%d+):([-]?%d+):([-]?%d+):(%d+):(%d+):(%d+)"); |
||
249 | if(id ~= nil) |
||
250 | then |
||
251 | local name = _GEM_IntToClass[id]; |
||
252 | classes[name] = {}; |
||
253 | classes[name].min = tonumber(mini,10); |
||
254 | classes[name].max = tonumber(maxi,10); |
||
255 | classes[name].tit_count = tonumber(tit,10); |
||
256 | classes[name].sub_count = tonumber(sub,10); |
||
257 | classes[name].repl_count = tonumber(repl,10); |
||
258 | end |
||
259 | end |
||
260 | end |
||
261 | end |
||
262 | return classes; |
||
263 | end |
||
264 | |||
265 | local function _GEM_COM_UnpackSubscribers(subs,subtype) |
||
266 | local subscribers = {}; |
||
267 | local pos = 1; |
||
268 | |||
269 | if(subs and subs ~= "") |
||
270 | then |
||
271 | for c in string.gfind(subs,_GEM_PARSE_PATTERN_SUB_PATTERN) |
||
272 | do |
||
273 | if(c ~= "") |
||
274 | then |
||
275 | local _,_,pl_name,id,level_str = string.find(c,"([^:]+):(%d+):(%d+)"); |
||
276 | if(id ~= nil) |
||
277 | then |
||
278 | local class = _GEM_IntToClass[id]; |
||
279 | local level = tonumber(level_str,10); |
||
280 | tinsert(subscribers, {place = subtype..pos; name = pl_name; guild=GEM_NA_FORMAT; class=class; level=level}); |
||
281 | pos = pos + 1; |
||
282 | end |
||
283 | end |
||
284 | end |
||
285 | end |
||
286 | return subscribers; |
||
287 | end |
||
288 | |||
289 | local function _GEM_COM_UnpackPlayers(pls) |
||
290 | local players = {}; |
||
291 | |||
292 | if(pls and pls ~= "") |
||
293 | then |
||
294 | for c in string.gfind(pls,_GEM_PARSE_PATTERN_SUB_PATTERN) |
||
295 | do |
||
296 | if(c ~= "") |
||
297 | then |
||
298 | local _,_,pl_name,id,level_str,stamp_str,forcesub_str,guild,comment = string.find(c,"([^:]+):(%d+):(%d+):(%d+):(%d+):([^:]*):(.*)"); |
||
299 | if(id ~= nil) |
||
300 | then |
||
301 | local class = _GEM_IntToClass[id]; |
||
302 | local level = tonumber(level_str,10); |
||
303 | local stamp = tonumber(stamp_str,10); |
||
304 | local forcesub = tonumber(forcesub_str,10); |
||
305 | players[pl_name] = {class=class; level=level; update_time=stamp; forcesub=forcesub; guild=guild; comment=comment}; |
||
306 | end |
||
307 | end |
||
308 | end |
||
309 | end |
||
310 | |||
311 | return players; |
||
312 | end |
||
313 | |||
314 | local function _GEM_COM_UnpackBanned(bans) |
||
315 | local banned = {}; |
||
316 | |||
317 | if(bans and bans ~= "") |
||
318 | then |
||
319 | for c in string.gfind(bans,_GEM_PARSE_PATTERN_SUB_PATTERN) |
||
320 | do |
||
321 | if(c ~= "") |
||
322 | then |
||
323 | local _,_,pl_name,reason = string.find(c,"([^:]+):(.*)"); |
||
324 | if(id ~= nil) |
||
325 | then |
||
326 | banned[pl_name] = reason; |
||
327 | end |
||
328 | end |
||
329 | end |
||
330 | end |
||
331 | |||
332 | return banned; |
||
333 | end |
||
334 | |||
335 | local function _GEM_COM_GetPreviousPacket(from,ev_id,w) |
||
336 | local _,_,MoreCounter,param = string.find(w,_GEM_TOKEN_MORE.."(%d+)-(.*)"); |
||
337 | if(MoreCounter == nil) |
||
338 | then |
||
339 | GEM_ChatWarning("_GEM_COM_GetPreviousPacket : Failed to find MoreCounter in '"..w.."' from "..from); |
||
340 | return nil; |
||
341 | end |
||
342 | local params = _GEMComm_MultiplePackets[from..ev_id..MoreCounter]; |
||
343 | if(params == nil) |
||
344 | then |
||
345 | --GEM_ChatWarning("_GEM_COM_GetPreviousPacket : Params is nil in '"..w.."' from "..from); |
||
346 | return nil; |
||
347 | end |
||
348 | if(param == _GEM_TOKEN_EMPTY) |
||
349 | then |
||
350 | param = ""; |
||
351 | end |
||
352 | params[table.getn(params)] = params[table.getn(params)]..param; |
||
353 | return params,MoreCounter; |
||
354 | end |
||
355 | |||
356 | local function _GEM_COM_SaveMultiplePacket(from,ev_id,w,params) |
||
357 | local _,_,MoreCounter = string.find(w,_GEM_TOKEN_MORE.."(%d+)"); |
||
358 | if(MoreCounter == nil) |
||
359 | then |
||
360 | GEM_ChatWarning("_GEM_COM_SaveMultiplePacket : Failed to find MoreCounter in '"..w.."' from "..from); |
||
361 | return; |
||
362 | end |
||
363 | _GEMComm_MultiplePackets[from..ev_id..MoreCounter] = params; |
||
364 | end |
||
365 | |||
366 | local function _GEM_COM_ClearMultiplePacket(from,ev_id,MoreCounter) |
||
367 | _GEMComm_MultiplePackets[from..ev_id..MoreCounter] = nil; |
||
368 | end |
||
369 | |||
370 | function GEM_COM_PurgeQueueMessageForChannel(channel) |
||
371 | local i = 1; |
||
372 | while(i <= table.getn(_GEM_COM_QueuedMessages)) |
||
373 | do |
||
374 | local queue_chan = _GEM_COM_QueuedMessages[i].channel; |
||
375 | if(queue_chan == channel) |
||
376 | then |
||
377 | table.remove(_GEM_COM_QueuedMessages,i); |
||
378 | else |
||
379 | i = i + 1; |
||
380 | end |
||
381 | end |
||
382 | end |
||
383 | |||
384 | |||
385 | --[[ |
||
386 | function GEM_COM_ParseChannelMessage |
||
387 | Channel parsing function. |
||
388 | ]] |
||
389 | function GEM_COM_ParseChannelMessage(channel,from,message) |
||
390 | if(from == GEM_PlayerName) then return; end; -- Not interested by messages from me |
||
391 | GEM_CheckPlayerJoined(channel,from); |
||
392 | local _,i,version,cmd_stamp_id = string.find(message,"^<GEM([^>]+)>(%d+-%d+-[^%s%d-]+%d+)"); |
||
393 | if(cmd_stamp_id == nil) then return; end; |
||
394 | local _,_,cmd,stamp_str,ev_id = string.find(cmd_stamp_id,"(%d+)-(%d+)-([^%s%d-]+%d+)"); |
||
395 | if(cmd == nil or stamp_str == nil or ev_id == nil) then return; end; |
||
396 | local stamp = tonumber(stamp_str,10); |
||
397 | if(stamp == nil) then return; end; |
||
398 | |||
399 | -- Check version |
||
400 | local _,_,major,minor = string.find(version,"([^.]+)%.(.+)"); |
||
401 | if(major == nil) |
||
402 | then |
||
403 | GEM_ChatDebug(GEM_DEBUG_GLOBAL,from.." is using an old major version of GEM."); |
||
404 | return; |
||
405 | end |
||
406 | if(major ~= GEM_MAJOR) |
||
407 | then |
||
408 | if(major > GEM_MAJOR) |
||
409 | then |
||
410 | if(GEM_OldVersion == false) |
||
411 | then |
||
412 | GEM_ChatPrint(GEM_TEXT_UPGRADE_NEEDED); |
||
413 | GEM_ChatPrint("GEM home page : http://christophe.calmejane.free.fr/wow/gem"); |
||
414 | GEM_OldVersion = true; |
||
415 | end |
||
416 | else |
||
417 | GEM_ChatDebug(GEM_DEBUG_GLOBAL,from.." is using an old major version of GEM."); |
||
418 | end |
||
419 | return; |
||
420 | end |
||
421 | if(minor ~= GEM_MINOR) |
||
422 | then |
||
423 | if(minor > GEM_MINOR) |
||
424 | then |
||
425 | if(GEM_NewMinorVersion == false) |
||
426 | then |
||
427 | GEM_ChatPrint(GEM_TEXT_UPGRADE_SUGGESTED); |
||
428 | GEM_ChatPrint("GEM home page : http://christophe.calmejane.free.fr/wow/gem"); |
||
429 | GEM_NewMinorVersion = true; |
||
430 | end |
||
431 | else |
||
432 | GEM_ChatDebug(GEM_DEBUG_GLOBAL,from.." is using an old minor version of GEM."); |
||
433 | end |
||
434 | end |
||
435 | |||
436 | local msg = strsub(message,i+1); |
||
437 | |||
438 | if(ev_id ~= GEM_GLOBAL_CMD and GEM_EVT_CheckExpiredEvent(ev_id)) -- Message for an expired event, just return |
||
439 | then |
||
440 | return; |
||
441 | end |
||
442 | |||
443 | if(GEM_Events.realms[GEM_Realm].ignore[ev_id]) |
||
444 | then |
||
445 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"Event "..ev_id.." is in ignore list, discarding message"); |
||
446 | return; |
||
447 | end |
||
448 | |||
449 | if(_GEMComm_Dispatch[cmd] == nil) |
||
450 | then |
||
451 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"Unknown command : "..cmd.." from "..from); |
||
452 | return; |
||
453 | end |
||
454 | |||
455 | local params = {}; |
||
456 | local MoreCounter = nil; |
||
457 | for w in string.gfind(msg,_GEM_PARSE_PATTERN) |
||
458 | do |
||
459 | if(string.find(w,_GEM_TOKEN_MORE) ~= nil) -- Multiple packet |
||
460 | then |
||
461 | if(table.getn(params) == 0) -- First param -> Continued packet |
||
462 | then |
||
463 | params,MoreCounter = _GEM_COM_GetPreviousPacket(from,ev_id,w); |
||
464 | if(params == nil) -- Cannot find previous packet, just discard this one |
||
465 | then |
||
466 | return; |
||
467 | end |
||
468 | else -- Continued multiple packets |
||
469 | _GEM_COM_SaveMultiplePacket(from,ev_id,w,params); |
||
470 | MoreCounter = nil; |
||
471 | return; |
||
472 | end |
||
473 | else -- Not multiple packet |
||
474 | if(w == nil or w == _GEM_TOKEN_EMPTY) |
||
475 | then |
||
476 | table.insert(params,""); |
||
477 | else |
||
478 | table.insert(params,w); |
||
479 | end |
||
480 | end |
||
481 | end |
||
482 | if(MoreCounter ~= nil) |
||
483 | then |
||
484 | _GEM_COM_ClearMultiplePacket(from,ev_id,MoreCounter); |
||
485 | end |
||
486 | if(ev_id ~= GEM_GLOBAL_CMD and cmd ~= GEM_CMD_EVENT_UPDATE and cmd ~= GEM_CMD_EVENT_CLOSE and cmd ~= GEM_CMD_EVENT_LEADER) -- Not an Event msg (-> a cmd message) |
||
487 | then |
||
488 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"GEM_COM_ParseChannelMessage : Received command "..cmd.." from "..from.." for EventID "..ev_id); |
||
489 | if(GEM_CMD_ReceivedCommand(channel,cmd,from,stamp,ev_id,params) == false) -- This command does not need more processing, don't dispatch, and return now |
||
490 | then |
||
491 | return; |
||
492 | end |
||
493 | end |
||
494 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"GEM_COM_ParseChannelMessage : Dispatching command "..cmd.." from "..from.." for EventID "..ev_id.." : "..message); |
||
495 | _GEMComm_Dispatch[cmd](channel,from,stamp,ev_id,params); |
||
496 | end |
||
497 | |||
498 | local function _GEM_COM_BuildClassesString(classes) |
||
499 | local clas = ""; |
||
500 | if(classes ~= nil) |
||
501 | then |
||
502 | for name,tab in classes |
||
503 | do |
||
504 | clas = clas.._GEM_TOKEN_SUB_TOKEN.._GEM_ClassToInt[name]..":"..tab.min..":"..tab.max..":"..tab.tit_count..":"..tab.sub_count..":"..tab.repl_count; |
||
505 | end |
||
506 | end |
||
507 | return clas; |
||
508 | end |
||
509 | |||
510 | local function _GEM_COM_BuildSubscribersStrings(event) |
||
511 | local tits = ""; |
||
512 | local subs = ""; |
||
513 | local repls = ""; |
||
514 | |||
515 | for pos,tab in event.titulars do |
||
516 | tits = tits.._GEM_TOKEN_SUB_TOKEN..tab.name..":".._GEM_ClassToInt[tab.class]..":"..tab.level; |
||
517 | end |
||
518 | |||
519 | for pos,tab in event.substitutes do |
||
520 | subs = subs.._GEM_TOKEN_SUB_TOKEN..tab.name..":".._GEM_ClassToInt[tab.class]..":"..tab.level; |
||
521 | end |
||
522 | |||
523 | for pos,tab in event.replacements do |
||
524 | repls = repls.._GEM_TOKEN_SUB_TOKEN..tab.name..":".._GEM_ClassToInt[tab.class]..":"..tab.level; |
||
525 | end |
||
526 | |||
527 | return tits,subs,repls; |
||
528 | end |
||
529 | |||
530 | local function _GEM_COM_BuildPlayersString(event) |
||
531 | local pls = ""; |
||
532 | |||
533 | for name,tab in event.players do |
||
534 | pls = pls.._GEM_TOKEN_SUB_TOKEN..name..":".._GEM_ClassToInt[tab.class]..":"..tab.level..":"..tab.update_time..":"..tab.forcesub..":"..tab.guild..":"..tab.comment; |
||
535 | end |
||
536 | |||
537 | return pls; |
||
538 | end |
||
539 | |||
540 | local function _GEM_COM_BuildBannedString(event) |
||
541 | local bans = ""; |
||
542 | |||
543 | for name,reason in event.banned do |
||
544 | bans = bans.._GEM_TOKEN_SUB_TOKEN..name..":"..reason; |
||
545 | end |
||
546 | |||
547 | return bans; |
||
548 | end |
||
549 | |||
550 | --[[ |
||
551 | function _GEM_COM_SendMessage |
||
552 | Low level sending function |
||
553 | channel : String -- Channel to send message to |
||
554 | cmd : String -- Command to send |
||
555 | ev_id : String -- EventId command is refering to |
||
556 | stamp : Integer -- TimeStamp of the send (relative to leader of ev_id) |
||
557 | params : String/Int -- Params associated with command |
||
558 | ]] |
||
559 | local function _GEM_COM_SendMessage(channel,cmd,ev_id,stamp,...) |
||
560 | if(channel == nil) |
||
561 | then |
||
562 | channel = GEM_DefaultSendChannel; |
||
563 | -- DEBUG |
||
564 | GEM_ChatWarning("_GEM_COM_SendMessage : Channel not nil !!"); |
||
565 | end |
||
566 | local msg = ""; |
||
567 | for i=1, arg.n |
||
568 | do |
||
569 | local val = arg[i]; |
||
570 | if(val == nil) |
||
571 | then |
||
572 | val = _GEM_TOKEN_EMPTY; |
||
573 | elseif((type(val) == "string") and (val == "")) |
||
574 | then |
||
575 | val = _GEM_TOKEN_EMPTY; |
||
576 | end; |
||
577 | msg = msg.._GEM_TOKEN..val; |
||
578 | end |
||
579 | |||
580 | _GEM_COM_QueueMessage(channel,cmd,ev_id,stamp,msg); |
||
581 | end |
||
582 | |||
583 | --[[ |
||
584 | function _GEM_COM_PrepareAndSendCommand |
||
585 | Low level command storing and sending function |
||
586 | ev_id : String -- EventId command is refering to |
||
587 | cmd : String -- Command to store/send |
||
588 | pl_dest : String -- Name of player the command is destinated to |
||
589 | pl_src : String -- Name of player the command is originating from |
||
590 | ... : String/Int -- Params associated with command |
||
591 | ]] |
||
592 | local function _GEM_COM_PrepareAndSendCommand(ev_id,cmd,pl_dest,pl_src,...) |
||
593 | local stamp = time() - GEM_GetOffsetTime(ev_id); |
||
594 | local cmd_id = pl_dest.."-"..pl_src.."-"..stamp.."-"..cmd; |
||
595 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
596 | local params = {}; |
||
597 | |||
598 | if(event == nil) |
||
599 | then |
||
600 | return; |
||
601 | end |
||
602 | |||
603 | tinsert(params,event.leader); |
||
604 | tinsert(params,event.ev_date); |
||
605 | tinsert(params,"0"); -- Not ACKed |
||
606 | tinsert(params,pl_dest); |
||
607 | tinsert(params,pl_src); |
||
608 | |||
609 | for i=1, arg.n do -- Build params array to store command |
||
610 | if(arg[i] == nil) |
||
611 | then |
||
612 | tinsert(params,""); |
||
613 | else |
||
614 | tinsert(params,arg[i]); |
||
615 | end |
||
616 | end |
||
617 | |||
618 | -- Create the CMD struct for this ev_id, if it does not exist |
||
619 | if(GEM_Events.realms[GEM_Realm].commands[ev_id] == nil) |
||
620 | then |
||
621 | GEM_CMD_CreateCommands(event.channel,ev_id,event.leader,event.ev_date); |
||
622 | end |
||
623 | -- Save the command |
||
624 | GEM_CMD_CreateCommandId(ev_id,cmd_id,cmd,stamp,params); |
||
625 | |||
626 | _GEM_COM_SendMessage(event.channel,cmd,ev_id,stamp,event.leader,event.ev_date,0,pl_dest,pl_src,unpack(arg)); |
||
627 | end |
||
628 | |||
629 | |||
630 | --------------- Process functions --------------- |
||
631 | --[[ |
||
632 | Process EventUpdate : |
||
633 | Params[1] = update_time (INT) |
||
634 | Params[2] = leader (STRING) |
||
635 | Params[3] = ev_date (INT) |
||
636 | Params[4] = ev_place (STRING) |
||
637 | Params[5] = ev_comment (STRING) |
||
638 | Params[6] = max_count (INT) |
||
639 | Params[7] = min_lvl (INT) |
||
640 | Params[8] = max_lvl (INT) |
||
641 | Params[9] = classes (STRING) |
||
642 | Params[10] = Titulars (STRING) |
||
643 | Params[11] = Substitutes (STRING) |
||
644 | Params[12] = Replacements (STRING) |
||
645 | Params[13] = Sorttype (STRING) |
||
646 | Params[14] = Closed comment (STRING) |
||
647 | ]] |
||
648 | local function _GEM_COM_Process_EventUpdate(channel,from,stamp,ev_id,params) |
||
649 | local update_time = tonumber(params[1],10); |
||
650 | local ev_date = tonumber(params[3],10); |
||
651 | local max_count = tonumber(params[6],10); |
||
652 | local min_lvl = tonumber(params[7],10); |
||
653 | local max_lvl = tonumber(params[8],10); |
||
654 | |||
655 | if(update_time == nil or ev_date == nil or max_count == nil or min_lvl == nil or max_lvl == nil) |
||
656 | then |
||
657 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_EventUpdate : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
658 | return; |
||
659 | end |
||
660 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_EventUpdate : From="..from.." at "..date("%c",stamp).." for "..ev_id); |
||
661 | if(GEM_EVT_UpdateEvent(channel,ev_id,update_time,params[2],ev_date,params[4],params[5],max_count,min_lvl,max_lvl,_GEM_COM_UnpackClasses(params[9]),_GEM_COM_UnpackSubscribers(params[10],"P"),_GEM_COM_UnpackSubscribers(params[11],"S"),_GEM_COM_UnpackSubscribers(params[12],"R"),params[13],params[14])) |
||
662 | then |
||
663 | if((GEM_Events.realms[GEM_Realm].events[ev_id].offset_time == 0) or (params[2] == from)) -- Update offset, if I don't have one, or if msg is from the leader |
||
664 | then |
||
665 | GEM_SetOffsetStamp(ev_id,stamp); |
||
666 | end |
||
667 | end |
||
668 | end |
||
669 | |||
670 | --[[ |
||
671 | Process EventClose : |
||
672 | Params[1] = Comment (STRING) |
||
673 | ]] |
||
674 | local function _GEM_COM_Process_EventClose(channel,from,stamp,ev_id,params) |
||
675 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_EventClose : Close event not used right anymore !!"); |
||
676 | --GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_EventClose : From="..from.." at "..date("%c",stamp).." for "..ev_id); |
||
677 | --GEM_EVT_ClearEvent(ev_id,params[1],false); |
||
678 | --GEM_QUE_RemoveEventFromQueue(ev_id); |
||
679 | end |
||
680 | |||
681 | --[[ |
||
682 | Process EventLeader : |
||
683 | Params[1] = update_time (INT) |
||
684 | Params[2] = new leader (STRING) |
||
685 | Params[3] = ev_date (INT) |
||
686 | Params[4] = ev_place (STRING) |
||
687 | Params[5] = ev_comment (STRING) |
||
688 | Params[6] = max_count (INT) |
||
689 | Params[7] = min_lvl (INT) |
||
690 | Params[8] = max_lvl (INT) |
||
691 | Params[9] = classes (STRING) |
||
692 | Params[10] = Titulars (STRING) |
||
693 | Params[11] = Substitutes (STRING) |
||
694 | Params[12] = Replacements (STRING) |
||
695 | Params[13] = Sorttype (STRING) |
||
696 | Params[13] = Players (STRING) |
||
697 | Params[13] = Banned (STRING) |
||
698 | ]] |
||
699 | local function _GEM_COM_Process_EventLeader(channel,from,stamp,ev_id,params) |
||
700 | if(GEM_IsMyReroll(params[2])) -- If I'm the new leader, process |
||
701 | then |
||
702 | local update_time = tonumber(params[1],10); |
||
703 | local ev_date = tonumber(params[3],10); |
||
704 | local max_count = tonumber(params[6],10); |
||
705 | local min_lvl = tonumber(params[7],10); |
||
706 | local max_lvl = tonumber(params[8],10); |
||
707 | |||
708 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_EventLeader : From="..from.." at "..date("%c",stamp).." for "..ev_id..". I'm the new leader !"); |
||
709 | -- Remove event, so I can re-create it |
||
710 | GEM_Events.realms[GEM_Realm].events[ev_id] = nil; |
||
711 | GEM_EVT_AddEvent(channel,ev_id,time(),params[2],ev_date,params[4],params[5],max_count,min_lvl,max_lvl,_GEM_COM_UnpackClasses(params[9]),_GEM_COM_UnpackSubscribers(params[10],"P"),_GEM_COM_UnpackSubscribers(params[11],"S"),_GEM_COM_UnpackSubscribers(params[12],"R"),params[13]); |
||
712 | GEM_Events.realms[GEM_Realm].events[ev_id].players = _GEM_COM_UnpackPlayers(params[14]); |
||
713 | GEM_Events.realms[GEM_Realm].events[ev_id].banned = _GEM_COM_UnpackBanned(params[15]); |
||
714 | |||
715 | -- Update my list |
||
716 | GEM_NotifyGUI(GEM_NOTIFY_EVENT_UPDATE,ev_id); |
||
717 | |||
718 | -- Broadcast event, and we are done |
||
719 | --GEM_COM_BroadcastEvent(GEM_Events.realms[GEM_Realm].events[ev_id]); |
||
720 | GEM_COM_NotifyEventUpdate(ev_id); |
||
721 | end |
||
722 | end |
||
723 | |||
724 | --[[ |
||
725 | Process CmdSubscribe : |
||
726 | -- Common Cmd params |
||
727 | Params[1] = leader (STRING) -- Leader of the event |
||
728 | Params[2] = ev_date (INT) -- Date of the event |
||
729 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
730 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
731 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
732 | -- Specific Cmd params |
||
733 | Params[6] = Class (STRING) -- Class of the subscribing player |
||
734 | Params[7] = Guild (STRING) -- Guild of the subscribing player |
||
735 | Params[8] = Level (INT) -- Level of the subscribing player |
||
736 | Params[9] = ForceSub (INT) -- <1/0> Force or not, subscribing player to replacement queue |
||
737 | Params[10] = Comment (STRING) -- Subscribe comment string |
||
738 | ]] |
||
739 | local function _GEM_COM_Process_CmdSubscribe(channel,from,stamp,ev_id,params) |
||
740 | local ev_date = tonumber(params[2],10); |
||
741 | local pl_level = tonumber(params[8],10); |
||
742 | local forcesub = tonumber(params[9],10); |
||
743 | local leader = params[1]; |
||
744 | local pl_name = params[5]; |
||
745 | local pl_class = params[6]; |
||
746 | local pl_guild = params[7]; |
||
747 | local pl_comment = params[10]; |
||
748 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
749 | |||
750 | if(event == nil) |
||
751 | then |
||
752 | return; |
||
753 | end |
||
754 | |||
755 | if(ev_date == nil or pl_level == nil or forcesub == nil) |
||
756 | then |
||
757 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdSubscribe : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
758 | return; |
||
759 | end |
||
760 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdSubscribe : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4].." : "..params[6].." - "..pl_level.." - "..params[10]); |
||
761 | |||
762 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
763 | then |
||
764 | GEM_ChatWarning("_GEM_COM_Process_CmdSubscribe : Processing a command not for me"); |
||
765 | end |
||
766 | |||
767 | -- Check player's level |
||
768 | if(pl_level < event.min_lvl or pl_level > event.max_lvl) |
||
769 | then |
||
770 | GEM_COM_KickPlayer(ev_id,pl_name,GEM_TEXT_ERR_LEVEL_FAILED); |
||
771 | return; |
||
772 | end |
||
773 | |||
774 | if((event.players[pl_name] == nil) or (stamp > event.players[pl_name].update_time)) -- First time I see this, or the command is more recent than the last received |
||
775 | then |
||
776 | if(GEM_EVT_IsBanned(ev_id,pl_name)) -- Check player for BAN |
||
777 | then |
||
778 | GEM_COM_BanPlayer(ev_id,pl_name); -- Resend a BAN command |
||
779 | return; -- Then return (just ignore this CMD) |
||
780 | end |
||
781 | GEM_SUB_CreateSubscriber(ev_id,stamp,pl_name,pl_class,pl_guild,pl_level,pl_comment,forcesub,0); -- Creates the subscribe |
||
782 | GEM_NotifyGUI(GEM_NOTIFY_SUBSCRIBER,ev_id,pl_name); |
||
783 | end |
||
784 | end |
||
785 | |||
786 | --[[ |
||
787 | Process CmdUnsubscribe : |
||
788 | -- Common Cmd params |
||
789 | Params[1] = leader (STRING) -- Leader of the event |
||
790 | Params[2] = ev_date (INT) -- Date of the event |
||
791 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
792 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
793 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
794 | -- Specific Cmd params |
||
795 | Params[6] = Comment (STRING) -- Unsubscribe comment string |
||
796 | ]] |
||
797 | local function _GEM_COM_Process_CmdUnsubscribe(channel,from,stamp,ev_id,params) |
||
798 | local ev_date = tonumber(params[2],10); |
||
799 | local leader = params[1]; |
||
800 | local pl_name = params[5]; |
||
801 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
802 | |||
803 | if(event == nil) |
||
804 | then |
||
805 | return; |
||
806 | end |
||
807 | |||
808 | if(ev_date == nil) |
||
809 | then |
||
810 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdUnsubscribe : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
811 | return; |
||
812 | end |
||
813 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdUnsubscribe : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4].." : "..params[6]); |
||
814 | |||
815 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
816 | then |
||
817 | GEM_ChatWarning("_GEM_COM_Process_CmdUnsubscribe : Processing a command not for me"); |
||
818 | end |
||
819 | |||
820 | if((event.players[pl_name] ~= nil) and (stamp > event.players[pl_name].update_time)) -- Player exists, and the command is more recent than the last received |
||
821 | then |
||
822 | GEM_SUB_RemoveSubscriber(ev_id,pl_name,params[6]); -- Removes the subscriber |
||
823 | GEM_NotifyGUI(GEM_NOTIFY_UNSUBSCRIBER,ev_id,pl_name); |
||
824 | end |
||
825 | end |
||
826 | |||
827 | --[[ |
||
828 | Process CmdTitular : |
||
829 | -- Common Cmd params |
||
830 | Params[1] = leader (STRING) -- Leader of the event |
||
831 | Params[2] = ev_date (INT) -- Date of the event |
||
832 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
833 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
834 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
835 | -- Specific Cmd params |
||
836 | ]] |
||
837 | local function _GEM_COM_Process_CmdTitular(channel,from,stamp,ev_id,params) |
||
838 | local ev_date = tonumber(params[2],10); |
||
839 | local pl_name = params[4]; |
||
840 | |||
841 | if(ev_date == nil) |
||
842 | then |
||
843 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdTitular : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
844 | return; |
||
845 | end |
||
846 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdTitular : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4]); |
||
847 | |||
848 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
849 | then |
||
850 | GEM_ChatWarning("_GEM_COM_Process_CmdTitular : Processing a command not for me"); |
||
851 | end |
||
852 | |||
853 | GEM_SUB_SetTitular(ev_id,stamp,pl_name); |
||
854 | end |
||
855 | |||
856 | --[[ |
||
857 | Process CmdSubstitute : |
||
858 | -- Common Cmd params |
||
859 | Params[1] = leader (STRING) -- Leader of the event |
||
860 | Params[2] = ev_date (INT) -- Date of the event |
||
861 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
862 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
863 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
864 | -- Specific Cmd params |
||
865 | ]] |
||
866 | local function _GEM_COM_Process_CmdSubstitute(channel,from,stamp,ev_id,params) |
||
867 | local ev_date = tonumber(params[2],10); |
||
868 | local pl_name = params[4]; |
||
869 | |||
870 | if(ev_date == nil) |
||
871 | then |
||
872 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdSubstitute : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
873 | return; |
||
874 | end |
||
875 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdSubstitute : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4]); |
||
876 | |||
877 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
878 | then |
||
879 | GEM_ChatWarning("_GEM_COM_Process_CmdSubstitute : Processing a command not for me"); |
||
880 | end |
||
881 | |||
882 | GEM_SUB_SetSubstitute(ev_id,stamp,pl_name); |
||
883 | end |
||
884 | |||
885 | --[[ |
||
886 | Process CmdReplacement : |
||
887 | -- Common Cmd params |
||
888 | Params[1] = leader (STRING) -- Leader of the event |
||
889 | Params[2] = ev_date (INT) -- Date of the event |
||
890 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
891 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
892 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
893 | -- Specific Cmd params |
||
894 | ]] |
||
895 | local function _GEM_COM_Process_CmdReplacement(channel,from,stamp,ev_id,params) |
||
896 | local ev_date = tonumber(params[2],10); |
||
897 | local pl_name = params[4]; |
||
898 | |||
899 | if(ev_date == nil) |
||
900 | then |
||
901 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdReplacement : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
902 | return; |
||
903 | end |
||
904 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdReplacement : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4]); |
||
905 | |||
906 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
907 | then |
||
908 | GEM_ChatWarning("_GEM_COM_Process_CmdReplacement : Processing a command not for me"); |
||
909 | end |
||
910 | |||
911 | GEM_SUB_SetReplacement(ev_id,stamp,pl_name); |
||
912 | end |
||
913 | |||
914 | --[[ |
||
915 | Process CmdKick : |
||
916 | -- Common Cmd params |
||
917 | Params[1] = leader (STRING) -- Leader of the event |
||
918 | Params[2] = ev_date (INT) -- Date of the event |
||
919 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
920 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
921 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
922 | -- Specific Cmd params |
||
923 | Params[6] = Reason (STRING) -- Reason of the kick |
||
924 | ]] |
||
925 | local function _GEM_COM_Process_CmdKick(channel,from,stamp,ev_id,params) |
||
926 | local ev_date = tonumber(params[2],10); |
||
927 | local pl_name = params[4]; |
||
928 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
929 | |||
930 | if(ev_date == nil) |
||
931 | then |
||
932 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdKick : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
933 | return; |
||
934 | end |
||
935 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdKick : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4].." : "..params[6]); |
||
936 | |||
937 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
938 | then |
||
939 | GEM_ChatWarning("_GEM_COM_Process_CmdKick : Processing a command not for me"); |
||
940 | end |
||
941 | |||
942 | GEM_Events.realms[GEM_Realm].subscribed[ev_id] = nil; |
||
943 | GEM_Events.realms[GEM_Realm].kicked[ev_id] = params[6]; |
||
944 | |||
945 | if(event == nil) |
||
946 | then |
||
947 | return; |
||
948 | end |
||
949 | |||
950 | GEM_ChatPrint(GEM_TEXT_CHAT_KICKED..event.ev_place.." ("..event.leader..") : "..params[6]); |
||
951 | GEM_NotifyGUI(GEM_NOTIFY_MY_SUBSCRIPTION,ev_id); |
||
952 | end |
||
953 | |||
954 | --[[ |
||
955 | Process CmdBan : |
||
956 | -- Common Cmd params |
||
957 | Params[1] = leader (STRING) -- Leader of the event |
||
958 | Params[2] = ev_date (INT) -- Date of the event |
||
959 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
960 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
961 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
962 | -- Specific Cmd params |
||
963 | Params[6] = Reason (STRING) -- Reason of the ban |
||
964 | ]] |
||
965 | local function _GEM_COM_Process_CmdBan(channel,from,stamp,ev_id,params) |
||
966 | local ev_date = tonumber(params[2],10); |
||
967 | local pl_name = params[4]; |
||
968 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
969 | |||
970 | if(ev_date == nil) |
||
971 | then |
||
972 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdBan : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
973 | return; |
||
974 | end |
||
975 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdBan : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4].." : "..params[6]); |
||
976 | |||
977 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
978 | then |
||
979 | GEM_ChatWarning("_GEM_COM_Process_CmdBan : Processing a command not for me"); |
||
980 | end |
||
981 | |||
982 | GEM_Events.realms[GEM_Realm].subscribed[ev_id] = nil; |
||
983 | GEM_Events.realms[GEM_Realm].banned[ev_id] = params[6]; |
||
984 | |||
985 | if(event == nil) |
||
986 | then |
||
987 | return; |
||
988 | end |
||
989 | |||
990 | GEM_ChatPrint(GEM_TEXT_CHAT_BANNED..event.ev_place.." ("..event.leader..") : "..params[6]); |
||
991 | GEM_NotifyGUI(GEM_NOTIFY_MY_SUBSCRIPTION,ev_id); |
||
992 | end |
||
993 | |||
994 | --[[ |
||
995 | Process CmdUnBan : |
||
996 | -- Common Cmd params |
||
997 | Params[1] = leader (STRING) -- Leader of the event |
||
998 | Params[2] = ev_date (INT) -- Date of the event |
||
999 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
1000 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
1001 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
1002 | -- Specific Cmd params |
||
1003 | ]] |
||
1004 | local function _GEM_COM_Process_CmdUnBan(channel,from,stamp,ev_id,params) |
||
1005 | local ev_date = tonumber(params[2],10); |
||
1006 | local pl_name = params[4]; |
||
1007 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1008 | |||
1009 | if(ev_date == nil) |
||
1010 | then |
||
1011 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdUnBan : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
1012 | return; |
||
1013 | end |
||
1014 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdUnBan : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4]); |
||
1015 | |||
1016 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
1017 | then |
||
1018 | GEM_ChatWarning("_GEM_COM_Process_CmdUnBan : Processing a command not for me"); |
||
1019 | end |
||
1020 | |||
1021 | GEM_Events.realms[GEM_Realm].banned[ev_id] = nil; |
||
1022 | |||
1023 | if(event == nil) |
||
1024 | then |
||
1025 | return; |
||
1026 | end |
||
1027 | |||
1028 | GEM_ChatPrint(GEM_TEXT_CHAT_UNBANNED..event.ev_place.." ("..event.leader..")"); |
||
1029 | GEM_NotifyGUI(GEM_NOTIFY_MY_SUBSCRIPTION,ev_id); |
||
1030 | end |
||
1031 | |||
1032 | --[[ |
||
1033 | Process PlayerInfos : |
||
1034 | Params[1] = name (STRING) |
||
1035 | Params[2] = guild (STRING) |
||
1036 | Params[3] = location (STRING) |
||
1037 | Params[4] = level (INT) |
||
1038 | Params[5] = class (STRING) |
||
1039 | Params[6] = officer (INT) |
||
1040 | Params[7] = rank name (STRING) |
||
1041 | Params[8] = rank idx (INT) |
||
1042 | Params[9] = GEM-Version (STRING) |
||
1043 | Params[10] = Comment (STRING) |
||
1044 | ]] |
||
1045 | local function _GEM_COM_Process_Global_PlayerInfos(channel,from,stamp,ev_id,params) |
||
1046 | local pl_level = tonumber(params[4],10); |
||
1047 | local g_rank_idx = tonumber(params[8],10); |
||
1048 | |||
1049 | if(params[6] == nil or params[6] == "") |
||
1050 | then |
||
1051 | params[6] = "0"; |
||
1052 | end |
||
1053 | local officer = tonumber(params[6],10); |
||
1054 | |||
1055 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_Global_PlayerInfos : From="..from.." at "..date("%c",stamp).." Fill infos : "..params[2].." : "..params[3].." : "..pl_level.." : "..params[5]); |
||
1056 | GEM_PLAY_FillPlayerInfos(channel,params[1],params[2],params[3],pl_level,params[5],officer,params[7],g_rank_idx,params[9],params[10]); |
||
1057 | GEM_NotifyGUI(GEM_NOTIFY_PLAYER_INFOS); |
||
1058 | end |
||
1059 | |||
1060 | --[[ |
||
1061 | Process CmdAssistant : |
||
1062 | -- Common Cmd params |
||
1063 | Params[1] = leader (STRING) -- Leader of the event |
||
1064 | Params[2] = ev_date (INT) -- Date of the event |
||
1065 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
1066 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
1067 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
1068 | -- Specific Cmd params |
||
1069 | ]] |
||
1070 | local function _GEM_COM_Process_CmdAssistant(channel,from,stamp,ev_id,params) |
||
1071 | local ev_date = tonumber(params[2],10); |
||
1072 | local pl_name = params[4]; |
||
1073 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1074 | |||
1075 | if(ev_date == nil) |
||
1076 | then |
||
1077 | GEM_ChatDebug(GEM_DEBUG_PROTOCOL,"_GEM_COM_Process_CmdAssistant : WARNING : Malformed event from "..from.." for EventID "..ev_id); |
||
1078 | return; |
||
1079 | end |
||
1080 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_COM_Process_CmdAssistant : From="..from.." at "..date("%c",stamp).." for "..ev_id.." : From "..params[5].." to "..params[4]); |
||
1081 | |||
1082 | if(not GEM_IsMyReroll(params[4])) -- Not for me ?? |
||
1083 | then |
||
1084 | GEM_ChatWarning("_GEM_COM_Process_CmdAssistant : Processing a command not for me"); |
||
1085 | end |
||
1086 | |||
1087 | GEM_Events.realms[GEM_Realm].assistant[ev_id] = true; |
||
1088 | |||
1089 | if(event == nil) |
||
1090 | then |
||
1091 | return; |
||
1092 | end |
||
1093 | |||
1094 | GEM_ChatPrint(GEM_TEXT_CHAT_ASSISTANT..event.ev_place.." ("..event.leader..")"); |
||
1095 | GEM_NotifyGUI(GEM_NOTIFY_MY_SUBSCRIPTION,ev_id); |
||
1096 | end |
||
1097 | |||
1098 | |||
1099 | |||
1100 | --------------- Exported functions --------------- |
||
1101 | |||
1102 | GEM_oldChatFrame_OnEvent = ChatFrame_OnEvent; |
||
1103 | function GEM_newChatFrame_OnEvent(event) |
||
1104 | local channel = nil; |
||
1105 | if(arg9) |
||
1106 | then |
||
1107 | channel = strlower(arg9); |
||
1108 | end |
||
1109 | |||
1110 | -- There is a channel |
||
1111 | if ( strsub(event, 1, 8) == "CHAT_MSG" and channel and GEM_Realm and GEM_IsChannelInList(channel)) then |
||
1112 | local type = strsub(event, 10); |
||
1113 | if(string.find(type,"^CHANNEL")) |
||
1114 | then |
||
1115 | if(type == "CHANNEL") |
||
1116 | then |
||
1117 | if(string.find(arg1,"^<GEM")) -- A GEM message ? Don't display |
||
1118 | then |
||
1119 | return; |
||
1120 | end |
||
1121 | -- the message is shown in this ChatFrame ? |
||
1122 | local info; |
||
1123 | local found = 0; |
||
1124 | local channelLength = strlen(arg4); |
||
1125 | for index, value in this.channelList do |
||
1126 | if ( channelLength > strlen(value) ) then |
||
1127 | -- arg9 is the channel name without the number in front... |
||
1128 | if ( ((arg7 > 0) and (this.zoneChannelList[index] == arg7)) or (strlower(value) == channel) ) then |
||
1129 | found = 1; |
||
1130 | info = ChatTypeInfo["CHANNEL"..arg8]; |
||
1131 | break; |
||
1132 | end |
||
1133 | end |
||
1134 | end |
||
1135 | if ( (found == 0) or not info ) then |
||
1136 | return; |
||
1137 | end |
||
1138 | |||
1139 | -- unpack PIPE_ENTITIE |
||
1140 | arg1 = string.gsub(arg1,_GEM_PIPE_ENTITIE,"|"); |
||
1141 | |||
1142 | -- Check for alias |
||
1143 | if(GEM_COM_Channels[channel].aliasSet and GEM_COM_Channels[channel].aliasSet ~= "") -- Alias set ? Show alias name |
||
1144 | then |
||
1145 | event = "CHAT_MSG_"..GEM_COM_Channels[channel].aliasSet; |
||
1146 | arg4 = ""; |
||
1147 | --arg9 = GEM_COM_Channels[channel].aliasSet; |
||
1148 | end |
||
1149 | elseif(type ~= "CHANNEL_LIST") |
||
1150 | then |
||
1151 | return; |
||
1152 | end |
||
1153 | end |
||
1154 | end |
||
1155 | GEM_oldChatFrame_OnEvent(event); |
||
1156 | end |
||
1157 | ChatFrame_OnEvent = GEM_newChatFrame_OnEvent; |
||
1158 | |||
1159 | function GEM_COM_InitRoutines() |
||
1160 | -- Schedule routine |
||
1161 | if(_GEM_COM_RoutineScheduled == false) |
||
1162 | then |
||
1163 | GEMSystem_Schedule(0.050,_GEM_COM_ScheduledSendRoutine); |
||
1164 | GEMSystem_Schedule(10,_GEM_COM_ScheduledPlayerInfos); |
||
1165 | _GEM_COM_RoutineScheduled = true; |
||
1166 | end |
||
1167 | |||
1168 | end |
||
1169 | |||
1170 | function GEM_COM_JoinChannel(channel,password) |
||
1171 | if(GetChannelName(channel) == 0) |
||
1172 | then |
||
1173 | GEM_ConnectedPlayers[channel] = {}; -- Reset players |
||
1174 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_JoinChannel : Joining channel "..channel.." with password ("..tostring(password)..")"); |
||
1175 | local zoneChannel, channelName = JoinChannelByName(channel,password,DEFAULT_CHAT_FRAME:GetID()); |
||
1176 | if(channelName) |
||
1177 | then |
||
1178 | channel = channelName; |
||
1179 | end |
||
1180 | if(not zoneChannel) |
||
1181 | then |
||
1182 | return; |
||
1183 | end |
||
1184 | |||
1185 | local i = 1; |
||
1186 | while(DEFAULT_CHAT_FRAME.channelList[i]) |
||
1187 | do |
||
1188 | i = i + 1; |
||
1189 | end |
||
1190 | DEFAULT_CHAT_FRAME.channelList[i] = channel; |
||
1191 | DEFAULT_CHAT_FRAME.zoneChannelList[i] = zoneChannel; |
||
1192 | else |
||
1193 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_COM_JoinChannel : Already in channel "..channel); |
||
1194 | end |
||
1195 | end |
||
1196 | |||
1197 | function GEM_COM_LeaveChannel(channel) |
||
1198 | if(channel and GEM_COM_Channels[channel] and GEM_COM_Channels[channel].id ~= 0) |
||
1199 | then |
||
1200 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_COM_LeaveChannel : Leaving channel "..channel); |
||
1201 | LeaveChannelByName(channel); |
||
1202 | GEM_COM_Channels[channel].id = 0; |
||
1203 | GEM_COM_Channels[channel].aliasSet = nil; |
||
1204 | end |
||
1205 | end |
||
1206 | |||
1207 | function GEM_Comm_test() |
||
1208 | --GEM_ChatPrint("ok"); |
||
1209 | end |
||
1210 | |||
1211 | function GEM_COM_AliasChannel(channel,alias,slash) |
||
1212 | if(alias == nil or alias == "") |
||
1213 | then |
||
1214 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_COM_AliasChannel : Not installing Channel Alias and Slash command, no alias defined"); |
||
1215 | return; |
||
1216 | end |
||
1217 | |||
1218 | if(GEM_IsChannelJoined(channel)) |
||
1219 | then |
||
1220 | local id = GEM_COM_Channels[channel].id; |
||
1221 | local upper = string.upper(slash); |
||
1222 | GEM_COM_Channels[channel].aliasSet = upper; |
||
1223 | ChatTypeInfo[upper] = ChatTypeInfo["CHANNEL"..id]; |
||
1224 | ChatTypeInfo[upper].sticky = 1; |
||
1225 | |||
1226 | setglobal("CHAT_MSG_"..upper,alias); |
||
1227 | setglobal("CHAT_"..upper.."_GET", "["..alias.."] %s:\32"); |
||
1228 | setglobal("CHAT_"..upper.."_SEND", alias..":\32"); |
||
1229 | |||
1230 | SlashCmdList[upper] = GEM_Comm_test; |
||
1231 | setglobal("SLASH_"..upper.."1", "/"..slash); |
||
1232 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_COM_AliasChannel : Channel Alias and Slash command initialized !"); |
||
1233 | else |
||
1234 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_COM_AliasChannel : Not installing Channel Alias and Slash command, channel not joined yet"); |
||
1235 | end |
||
1236 | end |
||
1237 | |||
1238 | function GEM_COM_UnAliasChannel(channel,alias,slash) |
||
1239 | if(alias and alias ~= "") |
||
1240 | then |
||
1241 | local upper = string.upper(slash); |
||
1242 | if(DEFAULT_CHAT_FRAME.editBox.stickyType == upper) |
||
1243 | then |
||
1244 | DEFAULT_CHAT_FRAME.editBox.chatType = "SAY"; |
||
1245 | DEFAULT_CHAT_FRAME.editBox.stickyType = "SAY"; |
||
1246 | end |
||
1247 | |||
1248 | setglobal("CHAT_MSG_"..upper, nil); |
||
1249 | setglobal("CHAT_"..upper.."_GET", nil); |
||
1250 | setglobal("CHAT_"..upper.."_SEND", nil); |
||
1251 | |||
1252 | SlashCmdList[upper] = nil; |
||
1253 | setglobal("SLASH_"..upper.."1", nil); |
||
1254 | GEM_COM_Channels[channel].aliasSet = nil; |
||
1255 | GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEM_COM_UnAliasChannel : Channel Alias and Slash command Uninitialized !"); |
||
1256 | end |
||
1257 | end |
||
1258 | |||
1259 | |||
1260 | --[[ |
||
1261 | function GEM_COM_BroadcastEvent : |
||
1262 | Broadcast an event |
||
1263 | event : Array -- The event struct to broadcast |
||
1264 | ]] |
||
1265 | function GEM_COM_BroadcastEvent(event) |
||
1266 | if(event == nil) then return; end; |
||
1267 | |||
1268 | local clas = _GEM_COM_BuildClassesString(event.classes); |
||
1269 | local tits,subs,repls = _GEM_COM_BuildSubscribersStrings(event); |
||
1270 | |||
1271 | _GEM_COM_SendMessage(event.channel,GEM_CMD_EVENT_UPDATE,event.id,event.offset_time,event.update_time,event.leader,event.ev_date,event.ev_place,event.ev_comment,event.max_count,event.min_lvl,event.max_lvl,clas,tits,subs,repls,event.sorttype,event.closed_comment); |
||
1272 | end |
||
1273 | |||
1274 | --[[ |
||
1275 | function GEM_COM_SendAckCommand : |
||
1276 | Send an ACK for a cmd |
||
1277 | ev_id : String -- Event ID |
||
1278 | cmd_id : String -- Cmd ID to ACK |
||
1279 | ]] |
||
1280 | function GEM_COM_SendAckCommand(ev_id,cmd_id) |
||
1281 | local cmds = GEM_CMD_GetCommands(ev_id); |
||
1282 | |||
1283 | cmds.cmds[cmd_id].LastSend = time(); |
||
1284 | _GEM_COM_SendMessage(cmds.channel,cmds.cmds[cmd_id].cmd,ev_id,cmds.cmds[cmd_id].stamp,cmds.leader,cmds.ev_date,1,cmds.cmds[cmd_id].params[4],cmds.cmds[cmd_id].params[5]); |
||
1285 | end |
||
1286 | |||
1287 | --[[ |
||
1288 | function GEM_COM_SendForwardCommand : |
||
1289 | Forward the command to the new leader |
||
1290 | ]] |
||
1291 | function GEM_COM_SendForwardCommand(channel,cmd,ev_id,stamp,params) |
||
1292 | _GEM_COM_SendMessage(channel,cmd,ev_id,stamp,unpack(params)); |
||
1293 | end |
||
1294 | |||
1295 | --[[ |
||
1296 | function GEM_COM_BroadcastCommand |
||
1297 | Broadcast an ACK for a cmd |
||
1298 | ev_id : String -- Event ID |
||
1299 | cmd_id : String -- Cmd ID to send |
||
1300 | ]] |
||
1301 | function GEM_COM_BroadcastCommand(ev_id,cmd_id) |
||
1302 | local cmds = GEM_Events.realms[GEM_Realm].commands[ev_id]; |
||
1303 | local cmdtab = cmds.cmds[cmd_id]; |
||
1304 | |||
1305 | if(cmdtab == nil) |
||
1306 | then |
||
1307 | GEM_ChatWarning("GEM_COM_BroadcastCommand : Failed to find cmd_id '"..cmd_id.."'"); |
||
1308 | return; |
||
1309 | end |
||
1310 | if(not GEM_CMD_IsCommandAcked(ev_id,cmd_id)) |
||
1311 | then |
||
1312 | _GEM_COM_SendMessage(cmds.channel,cmdtab.cmd,ev_id,cmdtab.stamp,unpack(cmdtab.params)); |
||
1313 | end |
||
1314 | end |
||
1315 | |||
1316 | |||
1317 | |||
1318 | function GEM_NotifyGUI(cmd,...) |
||
1319 | if(_GEM_NotifyCallBackFunction == nil) then return; end; |
||
1320 | |||
1321 | _GEM_NotifyCallBackFunction(cmd,unpack(arg)); |
||
1322 | end |
||
1323 | |||
1324 | |||
1325 | --------------- GUI Exported functions --------------- |
||
1326 | |||
1327 | --[[ - GUI ENTRY POINT |
||
1328 | function GEM_SetNotifyCallback : |
||
1329 | Sets the Callback function for GUI notifications. |
||
1330 | CBFunc : Function -- The CB function : void (*func)(NotifyCommand,...) |
||
1331 | ]] |
||
1332 | function GEM_SetNotifyCallback(CBfunc) |
||
1333 | _GEM_NotifyCallBackFunction = CBfunc; |
||
1334 | end |
||
1335 | |||
1336 | --[[ - GUI ENTRY POINT |
||
1337 | function GEM_COM_CreateNewEvent : |
||
1338 | Creates a new event and broadcast it. |
||
1339 | channel : String -- Channel where is event is to be created |
||
1340 | ev_date : Integer -- Date/Hour of the event (number of sec since 1970) |
||
1341 | ev_place : String -- Place of the event |
||
1342 | ev_comment : String -- Comment for the event |
||
1343 | max_count : Integer -- Max players for the event |
||
1344 | min_lvl : Integer -- Minimum level |
||
1345 | max_lvl : Integer -- Maximim level |
||
1346 | classes : Array{class={min,max,tit_count,sub_count,repl_count},...} -- Min/Max/Titulars/Substitutes/Replacements players of each listed class for the event |
||
1347 | sorttype : String -- Sorting type to use |
||
1348 | -- |
||
1349 | Returns the event ID (String) used to Broadcast the event |
||
1350 | ]] |
||
1351 | function GEM_COM_CreateNewEvent(channel,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,sorttype) |
||
1352 | local ev_id; |
||
1353 | local creat_time = time(); |
||
1354 | local selected = GEM_GetSelectedReroll(); |
||
1355 | local infos = GEM_Events.realms[GEM_Realm].my_names[selected]; |
||
1356 | |||
1357 | GEM_Events.next_event_id = GEM_Events.next_event_id + 1; |
||
1358 | ev_id = selected..GEM_Events.next_event_id; |
||
1359 | GEM_EVT_AddEvent(channel,ev_id,creat_time,selected,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,{},{},{},sorttype); |
||
1360 | GEM_SUB_CreateSubscriber(ev_id,creat_time,selected,infos.class,infos.guild,infos.level,"",0,0); |
||
1361 | GEM_NotifyGUI(GEM_NOTIFY_NEW_EVENT,ev_id); |
||
1362 | return ev_id; |
||
1363 | end |
||
1364 | |||
1365 | --[[ - GUI ENTRY POINT |
||
1366 | function GEM_COM_ChangeLeader : |
||
1367 | Changes the leader of an event, and send him all needed data. New leader must have subscribed, and be online. |
||
1368 | ev_id : String -- Event ID to change leader of |
||
1369 | new_leader : String -- Name of the new leader |
||
1370 | ]] |
||
1371 | function GEM_COM_ChangeLeader(ev_id,new_leader) |
||
1372 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1373 | |||
1374 | if(event ~= nil) |
||
1375 | then |
||
1376 | if(event.players[new_leader] == nil) |
||
1377 | then |
||
1378 | GEM_ChatPrint("Cannot change leader of EventID "..ev_id..", because "..new_leader.." never subscribed to the event"); |
||
1379 | return; |
||
1380 | end |
||
1381 | if(not GEM_IsPlayerConnected(event.channel,new_leader)) |
||
1382 | then |
||
1383 | GEM_ChatPrint("Cannot change leader of EventID "..ev_id..", because "..new_leader.." is not connected"); |
||
1384 | return; |
||
1385 | end |
||
1386 | |||
1387 | -- Tag myself as having subscribed to the event |
||
1388 | local myself = event.players[event.leader]; |
||
1389 | if(myself ~= nil) |
||
1390 | then |
||
1391 | GEM_EVT_SubscribeMyself(ev_id,event.leader,myself.guild,myself.level,myself.class,myself.comment,myself.forcesub,"1"); -- Titular |
||
1392 | end |
||
1393 | |||
1394 | local clas = _GEM_COM_BuildClassesString(event.classes); |
||
1395 | local tits,subs,repls = _GEM_COM_BuildSubscribersStrings(event); |
||
1396 | local pls = _GEM_COM_BuildPlayersString(event); |
||
1397 | local bans = _GEM_COM_BuildBannedString(event); |
||
1398 | |||
1399 | _GEM_COM_SendMessage(event.channel,GEM_CMD_EVENT_LEADER,event.id,time(),event.update_time,new_leader,event.ev_date,event.ev_place,event.ev_comment,event.max_count,event.min_lvl,event.max_lvl,clas,tits,subs,repls,event.sorttype,pls,bans); |
||
1400 | -- Remove the event, and set new forwarder |
||
1401 | GEM_Events.realms[GEM_Realm].forward[ev_id] = new_leader; |
||
1402 | event.leader = new_leader; -- Change leader, and wait for update |
||
1403 | GEM_NotifyGUI(GEM_NOTIFY_EVENT_UPDATE,ev_id); |
||
1404 | end |
||
1405 | end |
||
1406 | |||
1407 | local function _GEM_COM_NotifyEventUpdate_Schedule(ev_id) -- Scheduled CB function |
||
1408 | if(_GEMComm_ScheduledUpdates[ev_id] == nil or GEM_Events.realms[GEM_Realm].events[ev_id] == nil) |
||
1409 | then |
||
1410 | return; |
||
1411 | end |
||
1412 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1413 | |||
1414 | event.update_time = time(); |
||
1415 | GEM_COM_BroadcastEvent(event); |
||
1416 | _GEMComm_ScheduledUpdates[ev_id] = nil; |
||
1417 | end |
||
1418 | |||
1419 | --[[ - GUI ENTRY POINT |
||
1420 | function GEM_NotifyEventUpdate : |
||
1421 | Notify all players of an update in the event (called only by leader of ev_id). |
||
1422 | ev_id : String -- Event ID to notify an update from |
||
1423 | ]] |
||
1424 | function GEM_COM_NotifyEventUpdate(ev_id) |
||
1425 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1426 | |||
1427 | if(event ~= nil) |
||
1428 | then |
||
1429 | if(not GEM_IsMyReroll(event.leader)) |
||
1430 | then |
||
1431 | GEM_ChatPrint("GEM_COM_NotifyEventUpdate : This Event ID does not belong to me ("..ev_id..")"); |
||
1432 | return; |
||
1433 | end |
||
1434 | if(_GEMComm_ScheduledUpdates[ev_id] == nil) -- Not yet scheduled for update |
||
1435 | then |
||
1436 | _GEMComm_ScheduledUpdates[ev_id] = 1; |
||
1437 | GEMSystem_Schedule(10,_GEM_COM_NotifyEventUpdate_Schedule,ev_id); -- Schedule in 10s |
||
1438 | end |
||
1439 | GEM_NotifyGUI(GEM_NOTIFY_EVENT_UPDATE,ev_id); |
||
1440 | end |
||
1441 | end |
||
1442 | |||
1443 | --[[ - GUI ENTRY POINT |
||
1444 | function GEM_COM_CloseEvent : |
||
1445 | Closes an event and broadcast it (called only by leader of ev_id). |
||
1446 | ev_id : String -- Event ID to close |
||
1447 | comment : String -- comment for closed event |
||
1448 | ]] |
||
1449 | function GEM_COM_CloseEvent(ev_id,comment) |
||
1450 | --local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1451 | --if(event and (event.LastCloseSent == nil or event.LastCloseSent < GEM_COM_LastJoinerTime)) |
||
1452 | --then |
||
1453 | --_GEM_COM_SendMessage(event.channel,GEM_CMD_EVENT_CLOSE,ev_id,time(),comment); |
||
1454 | --event.LastCloseSent = time(); |
||
1455 | --end |
||
1456 | --GEM_EVT_ClearEvent(ev_id,comment,false); |
||
1457 | GEM_ChatWarning("Call to GEM_COM_CloseEvent"); |
||
1458 | end |
||
1459 | |||
1460 | --[[ - GUI ENTRY POINT |
||
1461 | function GEM_COM_Subscribe : |
||
1462 | Subscribes to an event and broadcast it (Sent by player, once). |
||
1463 | ev_id : String -- Event ID to subscribe to |
||
1464 | forcesub : Int -- <1/0> If you want to be put directly in replacement queue ("take me if you can't find anyone") |
||
1465 | comment : String -- Comment to send with subscription |
||
1466 | -- |
||
1467 | Returns nil if ok, error string otherwise. |
||
1468 | ]] |
||
1469 | function GEM_COM_Subscribe(ev_id,forcesub,comment) |
||
1470 | local selected = GEM_GetSelectedReroll(); |
||
1471 | local infos = GEM_Events.realms[GEM_Realm].my_names[selected]; |
||
1472 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1473 | |||
1474 | if(event == nil) -- Event does not exist anymore |
||
1475 | then |
||
1476 | return "Event "..ev_id.." does not exist anymore"; |
||
1477 | end |
||
1478 | if(GEM_IsMyReroll(event.leader)) -- I'm the leader |
||
1479 | then |
||
1480 | return "Cannot re-subscribe my own event"; |
||
1481 | end |
||
1482 | if(GEM_Events.realms[GEM_Realm].banned[ev_id] ~= nil) |
||
1483 | then |
||
1484 | GEM_ChatPrint("I am banned from EventID "..ev_id.." : "..GEM_Events.realms[GEM_Realm].banned[ev_id]); |
||
1485 | return "I'm banned from Event "..ev_id.." : "..GEM_Events.realms[GEM_Realm].banned[ev_id]; |
||
1486 | end |
||
1487 | |||
1488 | if(GEM_Events.realms[GEM_Realm].subscribed[ev_id] ~= nil) |
||
1489 | then |
||
1490 | GEM_ChatDebug(GEM_DEBUG_GLOBAL,"GEM_COM_Subscribe : Already tagged for subscription !!"); |
||
1491 | return "Internal error : Already tagged for subscription"; |
||
1492 | end |
||
1493 | |||
1494 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_SUBSCRIBE,event.leader,selected,infos.class,infos.guild,infos.level,forcesub,comment); |
||
1495 | |||
1496 | GEM_EVT_SubscribeMyself(ev_id,selected,infos.class,infos.level,infos.class,comment,forcesub,"0"); -- Tag myself as having sent a subscription |
||
1497 | GEM_NotifyGUI(GEM_NOTIFY_MY_SUBSCRIPTION,ev_id); |
||
1498 | |||
1499 | return nil; |
||
1500 | end |
||
1501 | |||
1502 | --[[ - GUI ENTRY POINT |
||
1503 | function GEM_COM_Unsubscribe : |
||
1504 | Unsubscribes from an event and broadcast it (Sent by player, once). |
||
1505 | ev_id : String -- Event ID to unsubscribe from |
||
1506 | comment : String -- Comment to send with unsubscription |
||
1507 | ]] |
||
1508 | function GEM_COM_Unsubscribe(ev_id,comment) |
||
1509 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1510 | |||
1511 | if(event == nil) -- Event does not exist anymore |
||
1512 | then |
||
1513 | return; |
||
1514 | end |
||
1515 | if(GEM_IsMyReroll(event.leader)) -- Cannot remove ourself |
||
1516 | then |
||
1517 | GEM_ChatPrint("GEM_COM_Unsubscribe : Cannot unsubscribe from your own event !"); |
||
1518 | return; |
||
1519 | end |
||
1520 | |||
1521 | if(GEM_Events.realms[GEM_Realm].subscribed[ev_id] == nil) |
||
1522 | then |
||
1523 | GEM_ChatDebug(GEM_DEBUG_GLOBAL,"GEM_COM_Unsubscribe : I'm not tagged as having sent subscription !!"); |
||
1524 | return; |
||
1525 | end |
||
1526 | |||
1527 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_UNSUBSCRIBE,event.leader,GEM_Events.realms[GEM_Realm].subscribed[ev_id].name,comment); |
||
1528 | |||
1529 | GEM_Events.realms[GEM_Realm].subscribed[ev_id] = nil; |
||
1530 | GEM_Events.realms[GEM_Realm].assistant[ev_id] = nil; -- Reset assistant status |
||
1531 | GEM_NotifyGUI(GEM_NOTIFY_MY_SUBSCRIPTION,ev_id); |
||
1532 | end |
||
1533 | |||
1534 | --[[ - GUI ENTRY POINT |
||
1535 | function GEM_COM_TitularPlayer : |
||
1536 | Informs a player he is titular, from an event I'm the leader. |
||
1537 | ev_id : String -- Event ID |
||
1538 | pl_name : String -- Player to inform |
||
1539 | ]] |
||
1540 | function GEM_COM_TitularPlayer(ev_id,pl_name) |
||
1541 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1542 | |||
1543 | if(event ~= nil) |
||
1544 | then |
||
1545 | if(not GEM_IsMyReroll(event.leader)) |
||
1546 | then |
||
1547 | GEM_ChatPrint("GEM_COM_TitularPlayer : This Event ID does not belong to me ("..ev_id..")"); |
||
1548 | return; |
||
1549 | end |
||
1550 | if(GEM_IsMyReroll(pl_name)) -- pl_name is me ! |
||
1551 | then |
||
1552 | return; |
||
1553 | end |
||
1554 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_TITULAR,pl_name,event.leader); |
||
1555 | end |
||
1556 | end |
||
1557 | |||
1558 | --[[ - GUI ENTRY POINT |
||
1559 | function GEM_COM_SubstitutePlayer : |
||
1560 | Informs a player he is Substitute, from an event I'm the leader. |
||
1561 | ev_id : String -- Event ID |
||
1562 | pl_name : String -- Player to inform |
||
1563 | ]] |
||
1564 | function GEM_COM_SubstitutePlayer(ev_id,pl_name) |
||
1565 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1566 | |||
1567 | if(event ~= nil) |
||
1568 | then |
||
1569 | if(not GEM_IsMyReroll(event.leader)) |
||
1570 | then |
||
1571 | GEM_ChatPrint("GEM_COM_SubstitutePlayer : This Event ID does not belong to me ("..ev_id..")"); |
||
1572 | return; |
||
1573 | end |
||
1574 | if(GEM_IsMyReroll(pl_name)) -- pl_name is me ! |
||
1575 | then |
||
1576 | return; |
||
1577 | end |
||
1578 | local stamp = time(); |
||
1579 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_SUBSTITUTE,pl_name,event.leader); |
||
1580 | end |
||
1581 | end |
||
1582 | |||
1583 | --[[ - GUI ENTRY POINT |
||
1584 | function GEM_COM_ReplacementPlayer : |
||
1585 | Informs a player he is Replacement, from an event I'm the leader. |
||
1586 | ev_id : String -- Event ID |
||
1587 | pl_name : String -- Player to inform |
||
1588 | ]] |
||
1589 | function GEM_COM_ReplacementPlayer(ev_id,pl_name) |
||
1590 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1591 | |||
1592 | if(event ~= nil) |
||
1593 | then |
||
1594 | if(not GEM_IsMyReroll(event.leader)) |
||
1595 | then |
||
1596 | GEM_ChatPrint("GEM_COM_ReplacementPlayer : This Event ID does not belong to me ("..ev_id..")"); |
||
1597 | return; |
||
1598 | end |
||
1599 | if(GEM_IsMyReroll(pl_name)) -- pl_name is me ! |
||
1600 | then |
||
1601 | return; |
||
1602 | end |
||
1603 | local stamp = time(); |
||
1604 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_REPLACEMENT,pl_name,event.leader); |
||
1605 | end |
||
1606 | end |
||
1607 | |||
1608 | --[[ - GUI ENTRY POINT |
||
1609 | function GEM_COM_KickPlayer : |
||
1610 | Kicks a player from an event I'm the leader. |
||
1611 | ev_id : String -- Event ID |
||
1612 | pl_name : String -- Player to kick from event |
||
1613 | reason : String -- Why you kick him |
||
1614 | ]] |
||
1615 | function GEM_COM_KickPlayer(ev_id,pl_name,reason) |
||
1616 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1617 | |||
1618 | if(event == nil) -- Event does not exist anymore |
||
1619 | then |
||
1620 | return; |
||
1621 | end |
||
1622 | if(GEM_IsMyReroll(pl_name)) -- Cannot remove ourself |
||
1623 | then |
||
1624 | GEM_ChatPrint("Cannot kick myself !"); |
||
1625 | return; |
||
1626 | end |
||
1627 | |||
1628 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_KICK,pl_name,event.leader,reason); |
||
1629 | |||
1630 | GEM_SUB_RemoveSubscriber(ev_id,pl_name,reason); -- Removes the subscriber |
||
1631 | GEM_NotifyGUI(GEM_NOTIFY_UNSUBSCRIBER,ev_id,pl_name); |
||
1632 | end |
||
1633 | |||
1634 | --[[ - GUI ENTRY POINT |
||
1635 | function GEM_COM_BanPlayer : |
||
1636 | Bans a player from an event I'm the leader. |
||
1637 | ev_id : String -- Event ID |
||
1638 | pl_name : String -- Player to ban from event |
||
1639 | reason : String -- Why you ban him |
||
1640 | ]] |
||
1641 | function GEM_COM_BanPlayer(ev_id,pl_name,reason) |
||
1642 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1643 | |||
1644 | if(event == nil) -- Event does not exist anymore |
||
1645 | then |
||
1646 | return; |
||
1647 | end |
||
1648 | if(GEM_IsMyReroll(pl_name)) -- Cannot remove ourself |
||
1649 | then |
||
1650 | GEM_ChatPrint("Cannot ban myself !"); |
||
1651 | return; |
||
1652 | end |
||
1653 | |||
1654 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_BAN,pl_name,event.leader,reason); |
||
1655 | |||
1656 | GEM_SUB_RemoveSubscriber(ev_id,pl_name,reason); -- Removes the subscriber |
||
1657 | GEM_EVT_SetBanned(ev_id,pl_name,reason); -- And now ban him |
||
1658 | GEM_NotifyGUI(GEM_NOTIFY_UNSUBSCRIBER,ev_id,pl_name); |
||
1659 | end |
||
1660 | |||
1661 | --[[ - GUI ENTRY POINT |
||
1662 | function GEM_COM_UnBanPlayer : |
||
1663 | UnBans a player from an event I'm the leader. |
||
1664 | ev_id : String -- Event ID |
||
1665 | pl_name : String -- Player to unban from event |
||
1666 | ]] |
||
1667 | function GEM_COM_UnBanPlayer(ev_id,pl_name) |
||
1668 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1669 | |||
1670 | if(event == nil) -- Event does not exist anymore |
||
1671 | then |
||
1672 | return; |
||
1673 | end |
||
1674 | |||
1675 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_UNBAN,pl_name,event.leader); |
||
1676 | |||
1677 | GEM_EVT_SetUnBanned(ev_id,pl_name); -- And now unban him |
||
1678 | end |
||
1679 | |||
1680 | --[[ - GUI ENTRY POINT |
||
1681 | function GEM_COM_PlayerInfos : |
||
1682 | Sends my player informations to all channels. |
||
1683 | ]] |
||
1684 | function GEM_COM_PlayerInfos() |
||
1685 | for channel,chantab in GEM_COM_Channels |
||
1686 | do |
||
1687 | if(chantab.id ~= 0) |
||
1688 | then |
||
1689 | _GEM_COM_LastPlayerInfosSend = time(); |
||
1690 | _GEM_COM_SendMessage(channel,GEM_CMD_PLAYER_INFOS,GEM_GLOBAL_CMD,time(),GEM_PLAY_GetMyPlayerInfos(channel)); |
||
1691 | end |
||
1692 | end |
||
1693 | end |
||
1694 | |||
1695 | --[[ - GUI ENTRY POINT |
||
1696 | function GEM_COM_PlayerInfosSingle : |
||
1697 | Sends my player informations to a single channel. |
||
1698 | ]] |
||
1699 | function GEM_COM_PlayerInfosSingle(channel) |
||
1700 | _GEM_COM_LastPlayerInfosSend = time(); |
||
1701 | _GEM_COM_SendMessage(channel,GEM_CMD_PLAYER_INFOS,GEM_GLOBAL_CMD,time(),GEM_PLAY_GetMyPlayerInfos(channel)); |
||
1702 | end |
||
1703 | |||
1704 | --[[ - GUI ENTRY POINT |
||
1705 | function GEM_COM_AddAssistant : |
||
1706 | Promotes a player assistant of an event I'm the leader. |
||
1707 | ev_id : String -- Event ID |
||
1708 | pl_name : String -- Player to promote assistant |
||
1709 | ]] |
||
1710 | function GEM_COM_AddAssistant(ev_id,pl_name) |
||
1711 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
1712 | |||
1713 | if(event == nil) -- Event does not exist anymore |
||
1714 | then |
||
1715 | return; |
||
1716 | end |
||
1717 | |||
1718 | event.assistants[pl_name] = 1; |
||
1719 | _GEM_COM_PrepareAndSendCommand(ev_id,GEM_CMD_CMD_ASSISTANT,pl_name,event.leader); |
||
1720 | end |
||
1721 | |||
1722 | |||
1723 | --------------- Plugin API --------------- |
||
1724 | |||
1725 | --[[ - PLUGIN API ENTRY POINT |
||
1726 | function GEM_COM_API_AddDispatchFunction : |
||
1727 | Adds a command dispatch callback function |
||
1728 | opcode : String -- Unique Opcode you want to use (must represent an Int) |
||
1729 | func : Function -- Function to be called when you receive this Opcode |
||
1730 | |||
1731 | Prototype for command related to an event = function CallbackFunc(channel,from,stamp,ev_id,params) : |
||
1732 | - channel = Channel event is linked to |
||
1733 | - from = Sender of the message |
||
1734 | - stamp = Stamp the command was issued by the author of the cmd (not necessary same person than 'from') |
||
1735 | - ev_id = EventId the command is related to |
||
1736 | - Common Cmd 'params' = |
||
1737 | Params[1] = leader (STRING) -- Leader of the event |
||
1738 | Params[2] = ev_date (INT) -- Date of the event |
||
1739 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
1740 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
1741 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
1742 | Followed by specific Cmd 'params' you pass to the Send function |
||
1743 | |||
1744 | Prototype for global command = function CallbackFunc(channel,from,stamp,ev_id,params) : |
||
1745 | - Same as previously, but ev_id = GEM_GLOBAL_CMD, and no 'common params', only 'specific params' |
||
1746 | |||
1747 | Global commands are volatile (not stored nor forwarded by other players), while event related commands are stored and broadcasted when a new player arrives. |
||
1748 | |||
1749 | Returns true on success, false if opcode is already in use |
||
1750 | ]] |
||
1751 | function GEM_COM_API_AddDispatchFunction(opcode,func) |
||
1752 | if(_GEMComm_Dispatch[tostring(opcode)] ~= nil) |
||
1753 | then |
||
1754 | return false; |
||
1755 | end |
||
1756 | _GEMComm_Dispatch[tostring(opcode)] = func; |
||
1757 | return true; |
||
1758 | end |
||
1759 | |||
1760 | --[[ - PLUGIN API ENTRY POINT |
||
1761 | function GEM_COM_API_SendVolatileCommand : |
||
1762 | Sends a volatile command (not stored nor forwarded by other players) |
||
1763 | channel : String -- Channel to send message to |
||
1764 | opcode : String -- Unique Opcode you want to use (must represent an Int) |
||
1765 | params : Table -- Array of your params (must be Int index based, use table.insert()) |
||
1766 | Returns true on success. |
||
1767 | ]] |
||
1768 | function GEM_COM_API_SendVolatileCommand(channel,opcode,params) |
||
1769 | _GEM_COM_SendMessage(channel,tostring(opcode),GEM_GLOBAL_CMD,time(),unpack(params)); |
||
1770 | return true; |
||
1771 | end |
||
1772 | |||
1773 | --[[ - PLUGIN API ENTRY POINT |
||
1774 | function GEM_COM_API_SendCommand : |
||
1775 | Sends an event related command (stored and broadcasted when a new player arrives) |
||
1776 | channel : String -- Channel to send message to |
||
1777 | opcode : String -- Unique Opcode you want to use (must represent an Int) |
||
1778 | ev_id : String -- EventId command is related to |
||
1779 | pl_dest : String -- Recipient player the message is addressed to |
||
1780 | pl_src : String -- Originator player (often the event.leader) |
||
1781 | params : Table -- Array of your params (must be Int index based, use table.insert()) |
||
1782 | Returns true on success, false if event is unknown. |
||
1783 | ]] |
||
1784 | function GEM_COM_API_SendCommand(channel,opcode,ev_id,pl_dest,pl_src,params) |
||
1785 | if(GEM_Events.realms[GEM_Realm].events[ev_id] == nil) |
||
1786 | then |
||
1787 | return false; |
||
1788 | end |
||
1789 | _GEM_COM_PrepareAndSendCommand(ev_id,tostring(opcode),pl_dest,pl_src,unpack(params)); |
||
1790 | return true; |
||
1791 | end |
||
1792 | |||
1793 | |||
1794 | --------------- Init dispatch table --------------- |
||
1795 | _GEMComm_Dispatch[GEM_CMD_EVENT_UPDATE] = _GEM_COM_Process_EventUpdate; |
||
1796 | _GEMComm_Dispatch[GEM_CMD_EVENT_CLOSE] = _GEM_COM_Process_EventClose; |
||
1797 | _GEMComm_Dispatch[GEM_CMD_EVENT_LEADER] = _GEM_COM_Process_EventLeader; |
||
1798 | _GEMComm_Dispatch[GEM_CMD_CMD_SUBSCRIBE] = _GEM_COM_Process_CmdSubscribe; |
||
1799 | _GEMComm_Dispatch[GEM_CMD_CMD_UNSUBSCRIBE] = _GEM_COM_Process_CmdUnsubscribe; |
||
1800 | _GEMComm_Dispatch[GEM_CMD_CMD_TITULAR] = _GEM_COM_Process_CmdTitular; |
||
1801 | _GEMComm_Dispatch[GEM_CMD_CMD_SUBSTITUTE] = _GEM_COM_Process_CmdSubstitute; |
||
1802 | _GEMComm_Dispatch[GEM_CMD_CMD_REPLACEMENT] = _GEM_COM_Process_CmdReplacement; |
||
1803 | _GEMComm_Dispatch[GEM_CMD_CMD_KICK] = _GEM_COM_Process_CmdKick; |
||
1804 | _GEMComm_Dispatch[GEM_CMD_CMD_BAN] = _GEM_COM_Process_CmdBan; |
||
1805 | _GEMComm_Dispatch[GEM_CMD_CMD_UNBAN] = _GEM_COM_Process_CmdUnBan; |
||
1806 | _GEMComm_Dispatch[GEM_CMD_PLAYER_INFOS] = _GEM_COM_Process_Global_PlayerInfos; |
||
1807 | _GEMComm_Dispatch[GEM_CMD_CMD_ASSISTANT] = _GEM_COM_Process_CmdAssistant; |
||
1808 | |||
1809 |