Advertisement
NovaYoshi

HandleServerMessage()

Dec 31st, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. function HandleServerMessage(S, Command, P) {
  2. // see https://wiki.f-list.net/F-Chat_Server_Commands
  3. print("Command received: "+Command);
  4. local Channel;
  5. switch(Command) {
  6. case "IDN": // identified
  7. S.Identified = true;
  8. break;
  9. case "VAR": // change variable
  10. S.VAR[P.variable] <- P.value;
  11. break;
  12. case "ADL": // list of chatops
  13. S.GlobalOps = P.ops;
  14. break;
  15. case "AOP": // someone has been promoted
  16. break;
  17. case "BRO": // broadcast
  18. api.Event("user notice", api.ToJSON({"Nick":"Global", "Text":api.ConvertBBCode(P.description)}), S.Tab);
  19. break;
  20. case "CDS": // change channel description
  21. Channel = S.Channels[P.channel];
  22. P.description = api.ConvertBBCode(P.description);
  23. if(Channel.Topic == "")
  24. api.Event("channel topic", api.ToJSON({"Text":P.description}), Channel.Tab);
  25. else
  26. api.Event("channel topic change", api.ToJSON({"Text":P.description}), Channel.Tab);
  27. Channel.Topic = P.description;
  28. break;
  29. case "CHA": // public channels list
  30. S.CHA = P.channels;
  31. break;
  32. case "ORS": // private channels list
  33. S.ORS = P.channels;
  34. break;
  35. case "CIU": // channel invite
  36. api.Event("you invite", api.ToJSON({"Nick":P.sender, "Channel":P.title, "JoinName":P.channel}), S.Tab);
  37. break;
  38. case "CBU": // channel ban
  39. Channel = S.Channels[P.channel];
  40. api.Event("channel ban+", api.ToJSON({"Nick":P.operator, "Target":P.character}), Channel.Tab);
  41. break;
  42. case "CKU": // channel kick
  43. Channel = S.Channels[P.channel];
  44. api.Event("channel kick", api.ToJSON({"Nick":P.operator, "Target":P.character}), Channel.Tab);
  45. break;
  46. case "COA": // channel promote
  47. Channel = S.Channels[P.channel];
  48. api.Event("channel status+", api.ToJSON({"Target":P.character, "Status":"operator"}), Channel.Tab);
  49. break;
  50. case "COR": // channel demote
  51. Channel = S.Channels[P.channel];
  52. api.Event("channel status-", api.ToJSON({"Target":P.character, "Status":"operator"}), Channel.Tab);
  53. break;
  54. case "COL": // channel operator list
  55. Channel = S.Channels[P.channel];
  56. Channel.Ops = P.oplist;
  57. break;
  58. case "CON": // number of users connected
  59. api.AddMessage("There are "+P.count+" users connected", S.Tab, 0, 0);
  60. break;
  61. case "CSO": // change owner
  62. Channel = S.Channels[P.channel];
  63. Channel.Ops[0] = P.character;
  64. api.Event("channel status+", api.ToJSON({"Target":P.character, "Status":"owner"}), Channel.Tab);
  65. break;
  66. case "CTU": // timeout user
  67. Channel = S.Channels[P.channel];
  68. api.Event("channel ban+", api.ToJSON({"Nick":P.operator, "Target":P.character, "Timeout":P.length}), Channel.Tab);
  69. break;
  70. case "DOP": // demote global op
  71. api.Event("channel status-", api.ToJSON({"Target":P.character, "Status":"operator"}), S.Tab);
  72. break;
  73. case "ERR": // error; todo: make more specific
  74. api.Event("generic error", api.ToJSON({"Text":P.message, "Number":P.number}), S.Tab);
  75. break;
  76. case "FKS": // search results
  77. break;
  78. case "FLN": // a character went offline
  79. // remove the user from all channels too
  80. delete S.GlobalUser[P.character];
  81. break;
  82. case "HLO": // hello
  83. api.AddMessage(P.message, S.Tab, 0, 0);
  84. break;
  85. case "JCH": // join
  86. Channel = GetOrMakeChannel(S, P.title, P.channel);
  87. api.Event("channel join", api.ToJSON({"Nick":P.character.identity}), Channel.Tab);
  88. break;
  89. case "ICH": // initial channel data
  90. Channel = S.Channels[P.channel];
  91. if(P.mode == "ads")
  92. NewChannel.ChatAllowed = false;
  93. else if(P.mode == "chat")
  94. NewChannel.AdsAllowed = false;
  95. Channel.Users = [];
  96. foreach(key,value in P.users)
  97. if(key=="identity")
  98. Channel.Users.append(value);
  99. break;
  100. case "KID": // reply to KIN
  101. break;
  102. case "LCH": // left channel
  103. // remove person from list
  104. Channel = S.Channels[P.channel];
  105. if(P.character == S.Character)
  106. api.Event("you part", api.ToJSON({"Nick":P.character}), Channel.Tab);
  107. else
  108. api.Event("channel part", api.ToJSON({"Nick":P.character}), Channel.Tab);
  109. break;
  110. case "LIS": // list of all users
  111. foreach(User in P.characters)
  112. S.GlobalUsers[User[0]] <- GlobalUser(User[0], User[1], User[2], User[3]);
  113. break;
  114. case "NLN": // user came online
  115. S.GlobalUsers[P.identity] <- GlobalUser(P.identity, P.gender, P.status, "");
  116. break;
  117. case "IGN": // ignore
  118. // todo: acknowledge add and delete?
  119. if(P.action == "init")
  120. S.IgnoreList = P.characters;
  121. break;
  122. case "FRL": // friends list and bookmarks list combined
  123. S.WatchList.extend(P.characters);
  124. break;
  125. case "PRD": // response to a PRO
  126. break;
  127. case "MSG": // channel message
  128. case "PRI": // private message
  129. local C = "";
  130. if(Command == "MSG")
  131. C = S.Channels[P.channel].Tab;
  132. else {
  133. if(!api.TabExists(S.Tab+"/"+P.character))
  134. C = api.TabCreate(P.character, S.Tab, TabFlags.QUERY)
  135. else
  136. C = S.Tab+"/"+P.character;
  137. }
  138. P.message = api.ConvertBBCode(P.message);
  139. if(P.message.len() > 4 && (P.message.tolower().slice(0, 4) == "/me "))
  140. api.Event("user action", api.ToJSON({"Nick":P.character, "Text":P.message.slice(4)}), C);
  141. else
  142. api.Event("user message", api.ToJSON({"Nick":P.character, "Text":P.message}), C);
  143. break;
  144. case "LRP": // RP ad
  145. Channel = S.Channels[P.channel];
  146. api.Event("advertisement", api.ToJSON({"Nick":P.character, "Text":api.ConvertBBCode(P.message)}), Channel.Tab);
  147. break;
  148. case "RLL": // roll, or bottle spin
  149. // todo
  150. break;
  151. case "RMO": // change room mode
  152. Channel = S.Channels[P.channel];
  153. Channel.ChatAllowed = true;
  154. Channel.AdsAllowed = true;
  155. if(P.mode == "chat")
  156. Channel.AdsAllowed = false;
  157. else if(P.mode == "ads")
  158. Channel.ChatAllowed = false;
  159. break;
  160. case "RTB": // real-time bridge; look for more information on this
  161. break;
  162. case "SFC": // reporting someone
  163. break;
  164. case "STA": // status change
  165. local Character = S.GlobalUsers[P.character];
  166. Character.Status = Statuses[P.status.tolower()];
  167. Character.StatusMessage = api.ConvertBBCode(P.statusmsg);
  168. break;
  169. case "SYS": // system message
  170. if("channel" in P)
  171. api.AddMessage(P.message, S.Channels[P.channel.toupper()].Tab, 0, 0);
  172. else
  173. api.AddMessage(P.message, S.Tab, 0, 0);
  174. break;
  175. case "TPN": // typing status
  176. break;
  177. case "UPT": // uptime and other info
  178. api.AddMessage("Started at:"+P.startstring+" Accepted:"+P.accepted+" Channels:"+P.channels+" Users:"+P.users+" MaxUsers:"+P.maxusers, S.Tab, 0, 0);
  179. break;
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement