public void OnUserSay(string nick, string message, int length, ref string[] args) { foreach (Module module in m_modules) { module.OnUserSay(nick, message, length, ref args); } Channel chan = GetChannel(); UserData user = chan != null?chan.GetUserData(nick) : null; if (user == null) { return; // Left channel or kicked player } // Command shortcuts: "$uno p" becomes "$p" unless escaped using "$$" if (user.cmd_scope != null && message[1] != '$') { if (user.cmd_scope.Run(nick, message.Substring(1))) { return; } } if (message[1] == '$') { // Unescape message = message.Substring(1); } m_chatcommands.Run(nick, message); }
public override void OnUserSay(string nick, string message, int length, ref string[] args) { Channel channel = p_manager.GetChannel(); string hostmask = channel.GetUserData(nick).hostmask; switch (args[0]) { case "$join": if (hostmask != G.settings["owner_hostmask"]) { channel.Say(nick + ": who are you?"); return; } if (args[1] != "") { E.Join(args[1]); } break; case "$part": if (hostmask != G.settings["owner_hostmask"]) { channel.Say(nick + ": who are you?"); return; } if (args[1] != "") { E.Part(args[1]); } break; } }
void Cmd_update(string nick, string message) { Channel channel = p_manager.GetChannel(); if (channel.GetUserData(nick).hostmask != G.settings["owner_hostmask"]) { channel.Say(nick + ": Permission denied"); return; } LoadGithubProjects(); channel.Say(nick + ": Updated! Got in total " + github_projects.Count + " Github projects to check."); }
void Cmd_join(string nick, string message) { Channel channel = p_manager.GetChannel(); LGameChannel game = GetLChannel(channel.GetName()); if (game != null && game.is_active) { channel.Say(nick + ": Please wait for " + game.GetPlayer() + " to finish their game."); return; } if (game != null && game.GetPlayer(nick) != null) { E.Notice(nick, "You already joined the game."); return; } if (game == null) { game = new LGameChannel(channel.GetName()); lchans.Add(game); } UserData user = channel.GetUserData(nick); user.cmd_scope = m_subcommand; game.players.Add(new LGPlayer(nick, user)); int count = game.players.Count; string text = "Player " + nick + " joined the game. Total " + count + " players ready."; if (count > 2) { text += " If you want to start the game, use \"$start\""; } else if (count == 1) { text += " At least 3 players are required to start the game."; } channel.Say(text); }
void Cmd_Join(string nick, string message) { Channel channel = p_manager.GetChannel(); UnoChannel uno = GetUnoChannel(channel.GetName()); if (uno != null && uno.is_active) { channel.Say(nick + ": Please wait for " + uno.current_player + " to finish their game."); return; } if (uno != null && uno.GetPlayer(nick) != null) { E.Notice(nick, "You already joined the game."); return; } // Create a new UnoChannel if (uno == null) { string modes_s = Chatcommand.GetNext(ref message); byte modes = 0x03; try { modes = Convert.ToByte(modes_s, 16); } catch { } uno = new UnoChannel(modes); m_channels[channel.GetName()] = uno; } UserData user = channel.GetUserData(nick); user.cmd_scope = m_subcommand; uno.players.Add(new UnoPlayer(nick, user)); uno.current_player = nick; channel.Say("[UNO] " + uno.players.Count + " player(s) are waiting for a new UNO game. " + string.Format("Modes: 0x{0:X2}", uno.modes)); }
string LuaRun(string nick, Channel chan, string message) { if (!System.IO.File.Exists("plugins/security.lua")) { return("Error: File 'plugins/security.lua' does not exist"); } bool is_private = chan.IsPrivate(); // Initialize packet lock, packet and start time lua_lock = false; lua_packet = new System.Text.StringBuilder(); SE.ResetLua(); SE.RegisterLuaFunction(l_print, "print"); SE.RegisterLuaFunction(l_stringldistance, "stringldistance"); SE.RegisterLuaFunction(l_getUserstatus, "getUserstatus"); Lua.lua_atpanic(SE.L, l_panic); #region Nick list Lua.lua_newtable(SE.L); int index = 0; if (!is_private) { foreach (var user in chan.users) { Lua.lua_pushinteger(SE.L, ++index); Lua.lua_newtable(SE.L); Lua.lua_pushstring(SE.L, "nick"); Lua.lua_pushstring(SE.L, user.Key); Lua.lua_settable(SE.L, -3); Lua.lua_pushstring(SE.L, "hostmask"); Lua.lua_pushstring(SE.L, user.Value.hostmask); Lua.lua_settable(SE.L, -3); Lua.lua_settable(SE.L, -3); } } Lua.lua_setglobal(SE.L, "N"); #endregion #region Public chat variables variables SE.CreateLuaTable("L"); Lua.lua_getglobal(SE.L, "L"); SE.SetTableField("channel", chan.GetName()); SE.SetTableField("nick", nick); SE.SetTableField("botname", G.settings["nickname"]); SE.SetTableField("hostmask", chan.GetUserData(nick).hostmask); SE.SetTableField("isprivate", is_private); SE.SetTableField("online", index); SE.SetTableField("owner_hostmask", G.settings["owner_hostmask"]); Lua.lua_settop(SE.L, 0); #endregion int lua_error = 1; string lua_output = null; lua_error = Lua.luaL_dofile(SE.L, "plugins/security.lua"); if (lua_error == 0) { lua_error = Lua.luaL_dostring(SE.L, message); } while (lua_lock) { System.Threading.Thread.Sleep(100); } int type = Lua.lua_type(SE.L, -1); if (type == Lua.LUA_TSTRING) { int length = Lua.lua_strlen(SE.L, -1); if (length > LUA_TEXT_MAX) { lua_output = "<too long message>"; Lua.lua_pop(SE.L, 1); type = Lua.LUA_TNONE; } } if (type != Lua.LUA_TNIL && type != Lua.LUA_TNONE) { lua_output = Lua.lua_tostring(SE.L, -1); } lua_lock = true; if (lua_output != null) { lua_packet.Append(lua_output); } if (lua_error > 0) { L.Log("m_Lua::LuaRun, errorcode = " + lua_error, true); } lua_lock = false; SE.CloseLua(); lua_timer.Reset(); #region Remove control characters, '\n' to space char[] answer = new char[LUA_TEXT_MAX]; int pos = 0; for (int i = 0; i < lua_packet.Length && pos < answer.Length; i++) { char cur = lua_packet[i]; if (cur == '\t' || cur == '\n') { cur = ' '; } if (cur == 0 || cur == '\r') { continue; } answer[pos] = cur; pos++; } #endregion if (pos == answer.Length) { answer[--pos] = '.'; answer[--pos] = '.'; answer[--pos] = ' '; pos += 3; } string answer_s = new string(answer, 0, pos); if (pos == 0) { answer_s = nick + ": <no return text>"; } return(answer_s); }
void FetchChat(string line) { //<host> 353 <NICKNAME> = #nimg_lobby :<nick> @<nick> +<nick> string[] args = line.Split(new char[] { ' ' }, 6); #region Nickname and Hostmask int read_pos = args[0].IndexOf('!'); string nick = ""; if (read_pos > 0) { nick = args[0].Substring(0, read_pos++); } else { read_pos = 0; } string hostmask = args[0].Substring(read_pos); #endregion string status = args[1].ToUpper(); #region Ping Pong if (hostmask == "PING") { status = status.ToLower(); if (status[0] == ':') { status = status.Substring(1); } L.Log("PONG to " + status); send("PONG " + status); if (OnPong != null) { OnPong(); } return; } if (hostmask == "PONG") { return; } #endregion if (status == "QUIT") { OnUserEvent(nick, hostmask, status, ""); return; } // <nick!host> <status> <destination> ... string destination = args[2]; #region JOIN NICK PART if (status == "JOIN" || status == "NICK" || status == "PART") { // <nick!host> PART <channel> // <nick!host> JOIN :<channel> if (destination[0] == ':') { destination = destination.Substring(1); } OnUserEvent(nick, hostmask, status, destination); return; } #endregion #region Normal Text-based // Check if it's possible to get the text right now bool is_text_only = false; for (int i = 0; i < TEXT_STATUS.Length; i++) { if (TEXT_STATUS[i] == status) { is_text_only = true; break; } } if (is_text_only) { // <nick!host> <status> <destination> :text text int min_start = args[0].Length + args[1].Length + args[2].Length + 3; read_pos = line.IndexOf(':', min_start) + 1; if (read_pos < 0) { Console.WriteLine(line); return; } string message = line.Substring(read_pos); if (status == "PONG") { L.Log(">> PONG " + hostmask); return; } if ((status == "PRIVMSG" || status == "NOTICE") && destination.ToUpper() != "AUTH" && destination != "*" && nick != "") { if (Channel.IsPrivate(destination)) { manager.SetActiveChannel(nick); // The tables have turned } else { manager.SetActiveChannel(destination); } Channel channel = manager.GetChannel(); // Update hostmask or add user { UserData user = channel.GetUserData(nick); if (user == null) { user = new UserData(hostmask); } else { user.hostmask = hostmask; } channel.users[nick] = user; } OnUserSay(nick, message); } else // numbers, AUTH request { OnServerMessage(status, destination, message); } return; } #endregion #region User Events // Userlist if (status == "332" || status == "353" || status == "366" || status == "396") { // <nick!host> 353 <destination> = <channel> :Bottybot figther212 @boots +Trivia foobar // <nick!host> <status> <destination> <channel> :Text text int min_start = 0; int text_start = (status == "353") ? 5 : 4; for (int i = 0; i < text_start; i++) { min_start += args[i].Length + 1; } read_pos = line.IndexOf(':', min_start) + 1; if (read_pos < 0) { L.Log("FetchChat() " + line, true); return; } string message = line.Substring(read_pos); OnServerMessage(status, args[text_start - 1], message); return; } if (status == "KICK") { // <nick!host> KICK <channel> <nick> :Kick reason OnUserEvent(args[3], "", status, destination); return; } #endregion if (status == "004" || status == "005" || status == "252" || status == "254" || status == "265" || status == "266" || status == "333") { // Ignore stuff that's not supported yet return; } Console.WriteLine(line); }
void Cmd_Join(string nick, string message) { Channel channel = p_manager.GetChannel(); UnoChannel uno = GetUnoChannel(channel.GetName()); if (uno != null && uno.is_active) { channel.Say(nick + ": Please wait for " + uno.current_player + " to finish their game."); return; } if (uno != null && uno.GetPlayer(nick) != null) { E.Notice(nick, "You already joined the game."); return; } // Create a new UnoChannel if (uno == null) { string modes_s = Chatcommand.GetNext(ref message); byte modes = 0x87; try { modes = Convert.ToByte(modes_s, 16); } catch { } uno = new UnoChannel(modes, m_settings); } if (uno.CheckMode(UnoMode.RANKED) && p_manager.GetUserStatus(nick) != 3) { E.Notice(nick, "You must be logged in to play ranked UNO."); return; } m_channels[channel.GetName()] = uno; // For new channels UserData user = channel.GetUserData(nick); user.cmd_scope = m_subcommand; var player = new UnoPlayer(nick, user); m_settings.Get(nick, ref player); uno.AddPlayer(player); // Human readable modes var modes_list = new List <string>(); for (int i = 1; i < byte.MaxValue; i <<= 1) { if ((uno.modes & i) > 0) { modes_list.Add(FormatMode((UnoMode)(uno.modes & i))); } } channel.Say("[UNO] " + uno.players.Count + " player(s) are waiting for a new UNO game. " + string.Format("Modes: [0x{0:X2}] ", uno.modes) + string.Join(", ", modes_list)); }