Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function HandleServerMessage(S, Command, P) {
- // see https://wiki.f-list.net/F-Chat_Server_Commands
- print("Command received: "+Command);
- local Channel;
- switch(Command) {
- case "IDN": // identified
- S.Identified = true;
- break;
- case "VAR": // change variable
- S.VAR[P.variable] <- P.value;
- break;
- case "ADL": // list of chatops
- S.GlobalOps = P.ops;
- break;
- case "AOP": // someone has been promoted
- break;
- case "BRO": // broadcast
- api.Event("user notice", api.ToJSON({"Nick":"Global", "Text":api.ConvertBBCode(P.description)}), S.Tab);
- break;
- case "CDS": // change channel description
- Channel = S.Channels[P.channel];
- P.description = api.ConvertBBCode(P.description);
- if(Channel.Topic == "")
- api.Event("channel topic", api.ToJSON({"Text":P.description}), Channel.Tab);
- else
- api.Event("channel topic change", api.ToJSON({"Text":P.description}), Channel.Tab);
- Channel.Topic = P.description;
- break;
- case "CHA": // public channels list
- S.CHA = P.channels;
- break;
- case "ORS": // private channels list
- S.ORS = P.channels;
- break;
- case "CIU": // channel invite
- api.Event("you invite", api.ToJSON({"Nick":P.sender, "Channel":P.title, "JoinName":P.channel}), S.Tab);
- break;
- case "CBU": // channel ban
- Channel = S.Channels[P.channel];
- api.Event("channel ban+", api.ToJSON({"Nick":P.operator, "Target":P.character}), Channel.Tab);
- break;
- case "CKU": // channel kick
- Channel = S.Channels[P.channel];
- api.Event("channel kick", api.ToJSON({"Nick":P.operator, "Target":P.character}), Channel.Tab);
- break;
- case "COA": // channel promote
- Channel = S.Channels[P.channel];
- api.Event("channel status+", api.ToJSON({"Target":P.character, "Status":"operator"}), Channel.Tab);
- break;
- case "COR": // channel demote
- Channel = S.Channels[P.channel];
- api.Event("channel status-", api.ToJSON({"Target":P.character, "Status":"operator"}), Channel.Tab);
- break;
- case "COL": // channel operator list
- Channel = S.Channels[P.channel];
- Channel.Ops = P.oplist;
- break;
- case "CON": // number of users connected
- api.AddMessage("There are "+P.count+" users connected", S.Tab, 0, 0);
- break;
- case "CSO": // change owner
- Channel = S.Channels[P.channel];
- Channel.Ops[0] = P.character;
- api.Event("channel status+", api.ToJSON({"Target":P.character, "Status":"owner"}), Channel.Tab);
- break;
- case "CTU": // timeout user
- Channel = S.Channels[P.channel];
- api.Event("channel ban+", api.ToJSON({"Nick":P.operator, "Target":P.character, "Timeout":P.length}), Channel.Tab);
- break;
- case "DOP": // demote global op
- api.Event("channel status-", api.ToJSON({"Target":P.character, "Status":"operator"}), S.Tab);
- break;
- case "ERR": // error; todo: make more specific
- api.Event("generic error", api.ToJSON({"Text":P.message, "Number":P.number}), S.Tab);
- break;
- case "FKS": // search results
- break;
- case "FLN": // a character went offline
- // remove the user from all channels too
- delete S.GlobalUser[P.character];
- break;
- case "HLO": // hello
- api.AddMessage(P.message, S.Tab, 0, 0);
- break;
- case "JCH": // join
- Channel = GetOrMakeChannel(S, P.title, P.channel);
- api.Event("channel join", api.ToJSON({"Nick":P.character.identity}), Channel.Tab);
- break;
- case "ICH": // initial channel data
- Channel = S.Channels[P.channel];
- if(P.mode == "ads")
- NewChannel.ChatAllowed = false;
- else if(P.mode == "chat")
- NewChannel.AdsAllowed = false;
- Channel.Users = [];
- foreach(key,value in P.users)
- if(key=="identity")
- Channel.Users.append(value);
- break;
- case "KID": // reply to KIN
- break;
- case "LCH": // left channel
- // remove person from list
- Channel = S.Channels[P.channel];
- if(P.character == S.Character)
- api.Event("you part", api.ToJSON({"Nick":P.character}), Channel.Tab);
- else
- api.Event("channel part", api.ToJSON({"Nick":P.character}), Channel.Tab);
- break;
- case "LIS": // list of all users
- foreach(User in P.characters)
- S.GlobalUsers[User[0]] <- GlobalUser(User[0], User[1], User[2], User[3]);
- break;
- case "NLN": // user came online
- S.GlobalUsers[P.identity] <- GlobalUser(P.identity, P.gender, P.status, "");
- break;
- case "IGN": // ignore
- // todo: acknowledge add and delete?
- if(P.action == "init")
- S.IgnoreList = P.characters;
- break;
- case "FRL": // friends list and bookmarks list combined
- S.WatchList.extend(P.characters);
- break;
- case "PRD": // response to a PRO
- break;
- case "MSG": // channel message
- case "PRI": // private message
- local C = "";
- if(Command == "MSG")
- C = S.Channels[P.channel].Tab;
- else {
- if(!api.TabExists(S.Tab+"/"+P.character))
- C = api.TabCreate(P.character, S.Tab, TabFlags.QUERY)
- else
- C = S.Tab+"/"+P.character;
- }
- P.message = api.ConvertBBCode(P.message);
- if(P.message.len() > 4 && (P.message.tolower().slice(0, 4) == "/me "))
- api.Event("user action", api.ToJSON({"Nick":P.character, "Text":P.message.slice(4)}), C);
- else
- api.Event("user message", api.ToJSON({"Nick":P.character, "Text":P.message}), C);
- break;
- case "LRP": // RP ad
- Channel = S.Channels[P.channel];
- api.Event("advertisement", api.ToJSON({"Nick":P.character, "Text":api.ConvertBBCode(P.message)}), Channel.Tab);
- break;
- case "RLL": // roll, or bottle spin
- // todo
- break;
- case "RMO": // change room mode
- Channel = S.Channels[P.channel];
- Channel.ChatAllowed = true;
- Channel.AdsAllowed = true;
- if(P.mode == "chat")
- Channel.AdsAllowed = false;
- else if(P.mode == "ads")
- Channel.ChatAllowed = false;
- break;
- case "RTB": // real-time bridge; look for more information on this
- break;
- case "SFC": // reporting someone
- break;
- case "STA": // status change
- local Character = S.GlobalUsers[P.character];
- Character.Status = Statuses[P.status.tolower()];
- Character.StatusMessage = api.ConvertBBCode(P.statusmsg);
- break;
- case "SYS": // system message
- if("channel" in P)
- api.AddMessage(P.message, S.Channels[P.channel.toupper()].Tab, 0, 0);
- else
- api.AddMessage(P.message, S.Tab, 0, 0);
- break;
- case "TPN": // typing status
- break;
- case "UPT": // uptime and other info
- api.AddMessage("Started at:"+P.startstring+" Accepted:"+P.accepted+" Channels:"+P.channels+" Users:"+P.users+" MaxUsers:"+P.maxusers, S.Tab, 0, 0);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement