//RMTSQD:pid:destsquad:sound:text public static void Try(string[] parameters) { if (string.IsNullOrEmpty(parameters[4]) || string.IsNullOrEmpty(parameters[2])) { return; } string squad = parameters[2].ToLower(); string name = Player.GetPlayerName(parameters[1]); string message = SiusUtil.Collate(4, parameters); if (SiusConf.GetSetting.Boolean("squadonlychat")) { //player is sending a squad message to a different squad if (Player.GetSquad(parameters[1]).ToLower() != squad) { SiusLog.Log(SiusLog.WARNING, "squad", name + " tried to send a message to a different squad (refer to settings - squadonlychat)."); return; } } //It's easier to blindly send the message //RMTSQD:destsquad:sender:sound:text Zone.BroadcastMessage("RMTSQD:" + squad + ":" + name + ":" + parameters[3] + ":" + message); SiusLog.Log(SiusLog.INFORMATION, "squad", name + " sent squad message to " + squad); SiusLog.Log(SiusLog.DEBUG, "squad", "Message: " + message); }
public static void Try(string[] parameters) { //RMT:pid:destination:sound:text string sender = Player.GetPlayerName(parameters[1]); string message = SiusUtil.Collate(4, parameters); for (int i = 0; i < Player.PlayerList.Count; i++) { Player.PlayerStruct p = (Player.PlayerStruct)Player.PlayerList[i]; if (p.name == parameters[2]) { try { TcpClient tcpZone = (TcpClient)Listen.htRcon[p.ZoneName]; StreamWriter swSenderSender; swSenderSender = new StreamWriter(tcpZone.GetStream()); //RMT:pid:sender:sound:text swSenderSender.WriteLine("RMT:" + p.pid + ":" + sender + ":" + parameters[3] + ":" + message); swSenderSender.Flush(); swSenderSender = null; } catch (Exception e) { SiusLog.Log(SiusLog.DEBUG, "remote", e.Message); } SiusLog.Log(SiusLog.INFORMATION, "remote", sender + " sent remote message to " + parameters[2]); SiusLog.Log(SiusLog.DEBUG, "remote", "Message: " + message); return; } } Message.Send = "MSG:" + parameters[1] + ":0:Unable to locate player."; SiusLog.Log(SiusLog.DEBUG, "remote", "Unable to locate and send remote message from " + sender + " to " + parameters[2]); SiusLog.Log(SiusLog.DEBUG, "remote", "Message: " + message); }
public static void Try(string[] parameters) { if (!string.IsNullOrEmpty(parameters[3])) { string name = Player.GetPlayerName(parameters[1]); string password = SiusUtil.Collate(3, parameters); if (password.Contains(":")) { Message.Send = "MSG:" + parameters[1] + ":0:Your password may not contain colons."; SiusLog.Log(SiusLog.DEBUG, "password", "Unable to change [" + name + "]'s password. Password contains a colon."); return; } //Check the password length if (password.Length < 1 || password.Length > 23) { Message.Send = "MSG:" + parameters[1] + ":0:The length of you password is invalid."; SiusLog.Log(SiusLog.DEBUG, "password", "Unable to change [" + name + "]'s password. Password length is invalid."); return; } password = SiusEncrypt.Encrypt(password, name, "players"); /* Begin Database Connection */ DataTable dt = new DataTable(); SQLiteConnection SConnection = new SQLiteConnection(); SConnection.ConnectionString = SQLite.ConnectionString; SConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(SConnection); cmd.CommandText = @"UPDATE 'players' SET password = @ppassword WHERE name = @pname"; SQLiteParameter ppassword = new SQLiteParameter("@ppassword"); SQLiteParameter pname = new SQLiteParameter("@pname"); cmd.Parameters.Add(ppassword); cmd.Parameters.Add(pname); ppassword.Value = password; pname.Value = name; cmd.ExecuteNonQuery(); SConnection.Close(); SConnection.Dispose(); /* End Database Connection */ Message.Send = "MSG:" + parameters[1] + ":0:Your password has been successfully changed."; SiusLog.Log(SiusLog.INFORMATION, "?password", "Successfully changed " + name + "'s password."); SiusLog.Log(SiusLog.DEBUG, "password", "Player [" + name + "] changed password to: " + password); } }
public static void Try(string[] parameters) { if (string.IsNullOrEmpty(parameters[3])) { string[] chats = Player.GetPlayerChat(parameters[1]); if (chats != null) { SendChatList(chats, parameters); SiusLog.Log(SiusLog.INFORMATION, "?chat", "Retrieved " + Player.GetPlayerName(parameters[1]) + "'s chat list."); return; } else { Message.Send = "MSG:" + parameters[1] + ":0:Empty."; } } else { Player.SetPlayerChat(parameters[1], SiusUtil.Collate(3, parameters)); SiusLog.Log(SiusLog.INFORMATION, "?chat", "Set " + Player.GetPlayerName(parameters[1]) + "'s chat list."); } }
public static void Try(string[] parameters) { Player.PlayerStruct p = Player.GetPlayer(parameters[1]); if (!string.IsNullOrEmpty(p.Squad)) { /* Begin Database Connection */ DataTable dt = new DataTable(); SQLiteConnection SConnection = new SQLiteConnection(); SConnection.ConnectionString = SQLite.ConnectionString; SConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(SConnection); cmd.CommandText = @"SELECT owner FROM squads WHERE name = @nsquad"; SQLiteParameter nsquad = new SQLiteParameter("@nsquad"); SQLiteParameter pname = new SQLiteParameter("@pname"); cmd.Parameters.Add(nsquad); cmd.Parameters.Add(pname); nsquad.Value = p.Squad; pname.Value = p.name; SQLiteDataReader Reader = cmd.ExecuteReader(); dt.Load(Reader); Reader.Close(); SConnection.Close(); /* End Database Connection */ if (dt.Rows.Count > 0) { if (dt.Rows[0][0].ToString().ToLower() == p.name.ToLower()) //if owner { string password = SiusUtil.Collate(3, parameters); if (string.IsNullOrEmpty(password)) { Message.Send = "MSG:" + parameters[1] + ":0:Please specify a password."; return; } if (password.Length > 23) { Message.Send = "MSG:" + parameters[1] + ":0:Password is too long."; return; } password = SiusEncrypt.Encrypt(password, p.Squad, "squads"); /* Begin Database Connection */ SConnection.Open(); cmd.CommandText = @"UPDATE squads SET password = @spass WHERE name = @nsquad"; SQLiteParameter spass = new SQLiteParameter("@spass"); cmd.Parameters.Add(spass); spass.Value = password; cmd.ExecuteNonQuery(); SConnection.Close(); /* End Database Connection */ Message.Send = "MSG:" + parameters[1] + ":0:Squad password successfully changed."; SiusLog.Log(SiusLog.INFORMATION, "?squadpassword", p.name + " successfully changed the password to squad <" + p.Squad + ">"); return; } else { Message.Send = "MSG:" + parameters[1] + ":0:You do not own this squad."; SiusLog.Log(SiusLog.INFORMATION, "?squadpassword", p.name + " attempted to change the password of <" + p.Squad + ">, but is not owner."); return; } } } Message.Send = "MSG:" + parameters[1] + ":0:You are not on a squad."; }
public static void Try(string[] parameters) { if (!string.IsNullOrEmpty(parameters[3])) { string squad = parameters[3]; string password = SiusUtil.Collate(4, parameters); string name = Player.GetPlayerName(parameters[1]); /* Begin Database Connection */ DataTable dt = new DataTable(); SQLiteConnection SConnection = new SQLiteConnection(); SConnection.ConnectionString = SQLite.ConnectionString; SConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(SConnection); cmd.CommandText = @"SELECT * FROM squads WHERE name = @nsquad"; SQLiteParameter nsquad = new SQLiteParameter("@nsquad"); cmd.Parameters.Add(nsquad); nsquad.Value = squad; SQLiteDataReader Reader = cmd.ExecuteReader(); dt.Load(Reader); Reader.Close(); SConnection.Close(); /* End Database Connection */ //The squad exists if (dt.Rows.Count > 0) { Message.Send = "MSG:" + parameters[1] + ":0:Sorry, this squad already exists."; SiusLog.Log(SiusLog.DEBUG, "?squadcreate", "Unable to create squad <" + squad + "> for " + name + ", but squad already exists."); SConnection.Dispose(); return; } else { SConnection.Open(); cmd.CommandText = @"INSERT INTO squads (name, owner, lastact) values (@nsquad, @pname, @last)"; SQLiteParameter last = new SQLiteParameter("@last"); SQLiteParameter pname = new SQLiteParameter("@pname"); cmd.Parameters.Add(last); cmd.Parameters.Add(pname); last.Value = System.DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); pname.Value = name; cmd.ExecuteNonQuery(); cmd.CommandText = @"UPDATE squads SET password = @spass WHERE name = @nsquad"; SQLiteParameter spass = new SQLiteParameter("@spass"); cmd.Parameters.Add(spass); spass.Value = SiusEncrypt.Encrypt(password, squad, "squads"); cmd.ExecuteNonQuery(); cmd.CommandText = @"UPDATE players SET squad = @nsquad WHERE name = @pname"; cmd.ExecuteNonQuery(); SConnection.Close(); SConnection.Dispose(); Message.Send = "MSG:" + parameters[1] + ":0:Squad successfully created. Please exit" + " your current zone and log back in for the change to take effect."; SiusLog.Log(SiusLog.INFORMATION, "?squadcreate", "Successfully created squad <" + squad + "> for " + name); return; } } }
public static string Try(string message) { // CONNECT:version:swname:zonename:hostname:password string[] parameters = message.Split(':'); string protocol = SiusConf.GetSetting.String("protocol"); string server = SiusConf.GetSetting.String("server"); string[] _protocol = protocol.Split(','); string[] _server = server.Split(','); Zone.ZoneName = parameters[3]; Zone.Software = parameters[2]; // Check if the number of parameters expected is different (e.g. zone name containing ':') if (parameters.Length != 6) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":Invalid connection protocol."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: Invalid connection protocol."); return(message); } // Check if the server is using the appropriate protocol if ((!SiusUtil.StringInArray(parameters[1], _protocol)) && (!string.IsNullOrEmpty(protocol))) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":Invalid protocol version."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: Unrecognized protocol version."); return(message); } // Check if the server is using a recognized type if ((!SiusUtil.StringInArray(parameters[2], _server)) && (!string.IsNullOrEmpty(server))) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":Invalid server version."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: Invalid server version."); return(message); } // Check if there are too many zones connected. if (!string.IsNullOrEmpty(SiusConf.GetSetting.String("maxzones"))) { if (Listen.htZones.Count >= SiusConf.GetSetting.Integer("maxzones")) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":There are too many zones currently connected."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: There are too many zones currently connected."); return(message); } } // Verify the password if (!string.IsNullOrEmpty(SiusConf.GetSetting.String("password"))) { if (parameters[5] != SiusConf.GetSetting.String("password")) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":Authentication failed: Invalid Password."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: Invalid Password."); return(message); } } // Check if the zone contains the illegal character ',' or if it's empty if (Zone.ZoneName.Contains(",") || string.IsNullOrEmpty(Zone.ZoneName)) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":The selected zone name is not valid."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: The selected zone name is not valid."); return(message); } // Check if a zone with this name already exists if (Listen.htRcon.Contains(Zone.ZoneName)) { message = "CONNECTBAD:Sius:" + SiusConf.GetSetting.String("network") + ":A zone with this name already exists."; SiusLog.Log(SiusLog.WARNING, "connect", Zone.ZoneName + " failed to connect: a zone with this name already exists."); return(message); } message = "CONNECTOK:Sius:" + SiusConf.GetSetting.String("network"); SiusLog.Log(SiusLog.INFORMATION, "connect", Zone.ZoneName + " successfully connected to the network."); return(message); }
public static void Try(string[] parameters) { //CHAT:pid:channel:sound:text string sender = ""; // the name of the sender string channel = ""; // the name of the chat channel Player.PlayerStruct p = Player.GetPlayer(parameters[1]); // Check if the player is sending to a valid channel if (p.Chat != null) { sender = p.name; int num; try { num = Convert.ToInt32(parameters[2]); } catch { num = 0; } if (num < p.Chat.Length) { channel = p.Chat[num]; } else { return; } } if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(sender)) { return; } // Send the message to every player on that chat for (int i = 0; i < Player.PlayerList.Count; i++) { Player.PlayerStruct pp = (Player.PlayerStruct)Player.PlayerList[i]; if (SiusUtil.StringInArray(channel, pp.Chat) && pp.name != sender) { try { TcpClient tcpZone = (TcpClient)Listen.htRcon[pp.ZoneName]; StreamWriter swSenderSender; swSenderSender = new StreamWriter(tcpZone.GetStream()); //CHATTXT:channel:sender:sound:text //CHAT:pid:number swSenderSender.WriteLine("CHATTXT:" + channel + ":" + sender + ":" + parameters[3] + ":" + SiusUtil.Collate(4, parameters)); if (pp.ZoneSW == "asss 1.4.3" || pp.ZoneSW == "asss 1.4.2") // Older versions are broken. { swSenderSender.WriteLine("CHAT:" + pp.pid + ":" + Array.IndexOf(pp.Chat, channel).ToString() + ":"); } else { swSenderSender.WriteLine("CHAT:" + pp.pid + ":" + Array.IndexOf(pp.Chat, channel).ToString()); } swSenderSender.Flush(); swSenderSender = null; } catch (Exception e) { SiusLog.Log(SiusLog.DEBUG, "chat", e.Message); } } } SiusLog.Log(SiusLog.INFORMATION, "chat", sender + " to " + channel + ": " + SiusUtil.Collate(4, parameters)); return; }
public static void Try(string[] parameters) { //CMD:pid:cmdname:name:text if (string.IsNullOrEmpty(parameters[3])) { Player.PlayerStruct p = Player.GetPlayer(parameters[1]); /* Begin Database Connection */ DataTable dt = new DataTable(); SQLiteConnection SConnection = new SQLiteConnection(); SConnection.ConnectionString = SQLite.ConnectionString; SConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(SConnection); cmd.CommandText = @"UPDATE 'messages' SET flag = 1 WHERE name = @pname;" + "SELECT * FROM 'messages' WHERE name = @pname"; SQLiteParameter pname = new SQLiteParameter("@pname"); cmd.Parameters.Add(pname); pname.Value = p.name; SQLiteDataReader Reader = cmd.ExecuteReader(); dt.Load(Reader); Reader.Close(); SConnection.Close(); /* End Database Connection */ // The player has no new messages if (dt.Rows.Count == 0) { Message.Send = "MSG:" + parameters[1] + ":0:You have no new messages."; SiusLog.Log(SiusLog.DEBUG, "?messages", "[" + p.name + "] has no new messages."); return; } TcpClient tcpZone = (TcpClient)p.tcpZone; StreamWriter swSenderSender; swSenderSender = new StreamWriter(tcpZone.GetStream()); for (int a = 0; a < dt.Rows.Count; a++) { string time = dt.Rows[a][3].ToString(); string sender = dt.Rows[a][1].ToString(); string message = dt.Rows[a][2].ToString(); swSenderSender.WriteLine("MSG:" + parameters[1] + ":0:" + "[" + time + "] " + sender + ": " + message); } swSenderSender.Flush(); swSenderSender = null; SiusLog.Log(SiusLog.INFORMATION, "?messages", "Sent [" + p.name + "] their messages."); return; } else { if (parameters.Length < 5) { return; } string receiver = parameters[3]; string message = SiusUtil.Collate(4, parameters); string name = Player.GetPlayerName(parameters[1]); /*SQLite.SendQuery("INSERT INTO 'messages' (name,sender,message,time) " + * "VALUES ('" + receiver + "','" + * name + "','" + message + "','" + * System.DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "');"); * * SiusLog.Log(SiusLog.DEBUG, "messages", "[" + name + "] sent [" + receiver + * "] the following message: " + message);*/ /* Begin Database Connection */ DataTable dt = new DataTable(); SQLiteConnection SConnection = new SQLiteConnection(); SConnection.ConnectionString = SQLite.ConnectionString; SQLiteCommand cmd = new SQLiteCommand(SConnection); SQLiteParameter apname = new SQLiteParameter("@pname"); cmd.Parameters.Add(apname); apname.Value = name; //Check maximum number of messages sent if (!string.IsNullOrEmpty(SiusConf.GetSetting.String("maxsent"))) { SConnection.Open(); cmd.CommandText = @"SELECT * FROM messages WHERE name = @pname"; SQLiteDataReader Reader = cmd.ExecuteReader(); dt.Load(Reader); Reader.Close(); SConnection.Close(); int rows = 0; for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][4].ToString() == "0") { rows++; } } if (rows >= SiusConf.GetSetting.Integer("maxsent")) { Message.Send = "MSG:" + parameters[1] + ":0:Error: Too many messages have been sent out." + " Please wait a while before trying again"; SConnection.Dispose(); SiusLog.Log(SiusLog.INFORMATION, "?message", "Unable to send <" + receiver + "> " + name + "'s message (too many pending messages sent)."); return; } dt.Clear(); } //Check maximum number of messages received if (!string.IsNullOrEmpty(SiusConf.GetSetting.String("maxinbox"))) { SConnection.Open(); cmd.CommandText = @"SELECT * FROM messages WHERE sender = @pname"; SQLiteDataReader Reader = cmd.ExecuteReader(); dt.Load(Reader); Reader.Close(); SConnection.Close(); int rows = 0; for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][4].ToString() == "0") { rows++; } } if (rows >= SiusConf.GetSetting.Integer("maxinbox")) { Message.Send = "MSG:" + parameters[1] + ":0:Error: This player's message inbox is full." + " Please try again at another time."; SConnection.Dispose(); SiusLog.Log(SiusLog.DEBUG, "?message", "Unable to send <" + receiver + "> " + name + "'s message (inbox full)."); return; } dt.Clear(); } //Send the message SConnection.Open(); cmd.CommandText = @"INSERT INTO 'messages' (name,sender,message,time) " + "VALUES (@receiver,@pname,@message,@utc);"; SQLiteParameter areceiver = new SQLiteParameter("@receiver"); SQLiteParameter amessage = new SQLiteParameter("@message"); SQLiteParameter autc = new SQLiteParameter("@utc"); cmd.Parameters.Add(areceiver); cmd.Parameters.Add(amessage); cmd.Parameters.Add(autc); areceiver.Value = receiver; amessage.Value = message; autc.Value = System.DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); cmd.ExecuteNonQuery(); SConnection.Close(); SConnection.Dispose(); /* End Database Connection */ Message.Send = "MSG:" + parameters[1] + ":0:Message has been sent to " + receiver; SiusLog.Log(SiusLog.INFORMATION, "?message", name + " sent " + receiver + " a message."); SiusLog.Log(SiusLog.DEBUG, "?message", "Message: " + message); } }
public static void Try(string[] parameters) { if (!string.IsNullOrEmpty(parameters[3])) { string squad = parameters[3]; string password = SiusUtil.Collate(4, parameters); /* Begin Database Connection */ DataTable dt = new DataTable(); SQLiteConnection SConnection = new SQLiteConnection(); SConnection.ConnectionString = SQLite.ConnectionString; SConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(SConnection); cmd.CommandText = @"SELECT * FROM squads WHERE name = @nsquad"; SQLiteParameter nsquad = new SQLiteParameter("@nsquad"); cmd.Parameters.Add(nsquad); nsquad.Value = squad; SQLiteDataReader Reader = cmd.ExecuteReader(); dt.Load(Reader); Reader.Close(); SConnection.Close(); /* End Database Connection */ //The squad exists if (dt.Rows.Count > 0) { //Check if the password is correct if (SiusEncrypt.Encrypt(password, squad, "squads") == dt.Rows[0][1].ToString()) { SConnection.Open(); cmd.CommandText = @"UPDATE players SET squad = @nsquad WHERE name = @pname"; SQLiteParameter pname = new SQLiteParameter("@pname"); cmd.Parameters.Add(pname); pname.Value = Player.GetPlayerName(parameters[1]); cmd.ExecuteNonQuery(); SConnection.Close(); SConnection.Dispose(); Message.Send = "MSG:" + parameters[1] + ":0:Your squad has been successfully changed." + " Please log back in for the change to take effect."; SiusLog.Log(SiusLog.INFORMATION, "?squadjoin", Player.GetPlayerName(parameters[1]) + " successfully joined squad <" + squad + ">."); return; } else { Message.Send = "MSG:" + parameters[1] + ":0:Invalid password for the specified squad."; SiusLog.Log(SiusLog.DEBUG, "?squadjoin", Player.GetPlayerName(parameters[1]) + " was unable to join squad <" + squad + "> (invalid password)."); } } else { Message.Send = "MSG:" + parameters[1] + ":0:This squad does not exist."; SiusLog.Log(SiusLog.DEBUG, "?squadjoin", Player.GetPlayerName(parameters[1]) + " was unable to join squad <" + squad + "> (squad does not exist)."); } } }
/// <summary> /// Handle logs sent from the zone. /// </summary> public static void Try(string[] parameters) { //TODO: Send this log to all online operators SiusLog.Log(SiusLog.WARNING, "zone", "(" + Zone.ZoneName + ") " + SiusUtil.Collate(1, parameters)); }