static public void Handle_CS_Chat(CS_PrivateChat <Zone> pkt, Zone zone) { DBServer server = zone._server; Chat chat = server.getChat(pkt.chat); //WTF MATE? if (chat == null) { Log.write(TLog.Error, "Handle_CS_Chat(): Unable to get chat."); return; } SC_PrivateChat <Zone> reply = new SC_PrivateChat <Zone>(); reply.chat = pkt.chat; reply.from = pkt.from; reply.message = pkt.message; reply.users = chat.List(); foreach (Zone z in server._zones) { if (z == null) { continue; } z._client.send(reply); } }
/// <summary> /// Creates a new packet based on the typeID and the received content /// inside the buffer. The user has to create an own implementation /// of this interface. /// </summary> public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size) { //Ready our packet base PacketBase packet = null; size--; //Was it a system packet? if (buffer[offset++] == 0) { //Yes, find the appropriate type return(createSystemPacket(typeID, buffer, offset, size)); } //So what was the typeid? switch (typeID) { case CS_Auth <T> .TypeID: packet = new CS_Auth <T>(typeID, buffer, offset, size); break; case CS_PlayerLogin <T> .TypeID: packet = new CS_PlayerLogin <T>(typeID, buffer, offset, size); break; case CS_PlayerUpdate <T> .TypeID: packet = new CS_PlayerUpdate <T>(typeID, buffer, offset, size); break; case CS_PlayerLeave <T> .TypeID: packet = new CS_PlayerLeave <T>(typeID, buffer, offset, size); break; case CS_PlayerBanner <T> .TypeID: packet = new CS_PlayerBanner <T>(typeID, buffer, offset, size); break; case CS_PlayerStatsRequest <T> .TypeID: packet = new CS_PlayerStatsRequest <T>(typeID, buffer, offset, size); break; case CS_Whisper <T> .TypeID: packet = new CS_Whisper <T>(typeID, buffer, offset, size); break; case CS_JoinChat <T> .TypeID: packet = new CS_JoinChat <T>(typeID, buffer, offset, size); break; case CS_LeaveChat <T> .TypeID: packet = new CS_LeaveChat <T>(typeID, buffer, offset, size); break; case CS_PrivateChat <T> .TypeID: packet = new CS_PrivateChat <T>(typeID, buffer, offset, size); break; case CS_ModCommand <T> .TypeID: packet = new CS_ModCommand <T>(typeID, buffer, offset, size); break; case CS_Squads <T> .TypeID: packet = new CS_Squads <T>(typeID, buffer, offset, size); break; case CS_ChatQuery <T> .TypeID: packet = new CS_ChatQuery <T>(typeID, buffer, offset, size); break; case Disconnect <T> .TypeID: packet = new Disconnect <T>(typeID, buffer, offset, size); break; case CS_Ban <T> .TypeID: packet = new CS_Ban <T>(typeID, buffer, offset, size); break; case CS_SquadMatch <T> .TypeID: packet = new CS_SquadMatch <T>(typeID, buffer, offset, size); break; case CS_ModQuery <T> .TypeID: packet = new CS_ModQuery <T>(typeID, buffer, offset, size); break; case CS_ChatCommand <T> .TypeID: packet = new CS_ChatCommand <T>(typeID, buffer, offset, size); break; case CS_StatsUpdate <T> .TypeID: packet = new CS_StatsUpdate <T>(typeID, buffer, offset, size); break; case CS_ArenaUpdate <T> .TypeID: packet = new CS_ArenaUpdate <T>(typeID, buffer, offset, size); break; default: //An undefined packet. packet = new PacketDummy(typeID, buffer, offset, size); break; } return(packet); }
{ /// <summary> /// Handles chat packets sent from the client /// </summary> static public void Handle_CS_Chat(CS_Chat pkt, Player player) { if (player == null) { Log.write(TLog.Error, "Handle_CS_Chat(): Called with null player."); return; } if (player._arena == null) { Log.write(TLog.Error, "Handle_CS_Chat(): Called with null arena."); return; } //Ignore blank messages if (pkt.message == "") { return; } //Is it a server command? if (pkt.message[0] == '?' && pkt.message.Length > 1) { //Obtain the command and payload int spcIdx = pkt.message.IndexOf(' '); string command; string payload = ""; if (spcIdx == -1) { command = pkt.message.Substring(1); } else { command = pkt.message.Substring(1, spcIdx - 1); payload = pkt.message.Substring(spcIdx + 1); } //Do we have a recipient? Player recipient = null; if (pkt.chatType == Helpers.Chat_Type.Whisper) { if ((recipient = player._server.getPlayer(pkt.recipient)) == null) { return; } } //Route it to our arena! player._arena.handleEvent(delegate(Arena arena) { arena.playerChatCommand(player, recipient, command, payload, pkt.bong); } ); return; } //Is it a Communication Command? else if (pkt.message[0] == '%' && pkt.message.Length > 1) { //Obtain the command and payload int spcIdx = pkt.message.IndexOf(' '); string command; string payload = ""; if (spcIdx == -1) { command = pkt.message.Substring(1); } else { command = pkt.message.Substring(1, spcIdx - 1); payload = pkt.message.Substring(spcIdx + 1); } //Do we have a recipient? Player recipient = null; if (pkt.chatType == Helpers.Chat_Type.Whisper) { if ((recipient = player._server.getPlayer(pkt.recipient)) == null) { return; } } //Route it to our arena! player._arena.handleEvent(delegate(Arena arena) { arena.playerCommCommand(player, recipient, command, payload, pkt.bong); } ); return; } //Is it a Mod Command? else if (pkt.message[0] == '*' && pkt.message.Length > 1) { //Obtain the command and payload int spcIdx = pkt.message.IndexOf(' '); string command; string payload = ""; if (spcIdx == -1) { command = pkt.message.Substring(1); } else { command = pkt.message.Substring(1, spcIdx - 1); payload = pkt.message.Substring(spcIdx + 1); } //Do we have a recipient? Player recipient = null; if (pkt.chatType == Helpers.Chat_Type.Whisper) { if ((recipient = player._server.getPlayer(pkt.recipient)) == null) { return; } } //Route it to our arena! player._arena.handleEvent(delegate(Arena arena) { player._arena.playerModCommand(player, recipient, command, payload, pkt.bong); } ); return; } else //Must be a regular chat, lets see if they are allowed first { //Ignore messages from the silent if (player._bSilenced) { player.sendMessage(-1, "You can't speak."); return; } //Lets do some spam checking.. bool change = false; player._msgTimeStamps.Add(DateTime.Now); foreach (DateTime msg in player._msgTimeStamps) { TimeSpan diff = DateTime.Now - msg; if (diff.Seconds > 5) { change = true; } } //Remove messages that are older than 5 seconds. //Clear player spam list, restart over if (player._msgTimeStamps != null && change) { player._msgTimeStamps = new List <DateTime>(); } //More than 5 messages in 5 seconds? if (player._msgTimeStamps.Count == 5) { //Warn him player.sendMessage(-1, "WARNING! You will be auto-silenced for spamming."); } //More than 10 messages in 5 seconds? if (player._msgTimeStamps.Count >= 10) { //Autosilence int duration = 5; //5 mins player.sendMessage(-1, String.Format("You are being auto-silenced for {0} minutes for spamming.", duration)); player._bSilenced = true; player._lengthOfSilence = duration; player._timeOfSilence = DateTime.Now; if (!player._arena._silencedPlayers.ContainsKey(player._alias)) { player._arena._silencedPlayers.Add(player._alias, duration); } return; } //For league matches bool Allowed = true; if (player._arena._isMatch && player.PermissionLevelLocal < Data.PlayerPermission.ArenaMod && player.IsSpectator) { Allowed = false; } //What sort of chat has occured? switch (pkt.chatType) { case Helpers.Chat_Type.Normal: //For leagues, dont allow them to talk to the teams if (!Allowed) { pkt.chatType = Helpers.Chat_Type.Team; Handle_CS_Chat(pkt, player); break; } if ((player._arena._specQuiet || player._specQuiet) && player.PermissionLevelLocal < Data.PlayerPermission.ArenaMod && player.IsSpectator) { pkt.chatType = Helpers.Chat_Type.Team; Handle_CS_Chat(pkt, player); break; } //Send it to our arena! player._arena.handleEvent(delegate(Arena arena) { pkt.bong = 0; player._arena.playerArenaChat(player, pkt); } ); break; case Helpers.Chat_Type.Macro: if (!Allowed) { //Arent allowed pkt.chatType = Helpers.Chat_Type.Team; Handle_CS_Chat(pkt, player); break; } if ((player._arena._specQuiet || player._specQuiet) && player.PermissionLevelLocal < Data.PlayerPermission.ArenaMod && player.IsSpectator) { pkt.chatType = Helpers.Chat_Type.Team; Handle_CS_Chat(pkt, player); break; } pkt.chatType = Helpers.Chat_Type.Normal; Handle_CS_Chat(pkt, player); break; case Helpers.Chat_Type.Team: //Send it to the player's team player._team.playerTeamChat(player, pkt); if (player.IsSpectator) { player._server.ircClient.SendMessage( Meebey.SmartIrc4net.SendType.Message, player._arena.IrcName, String.Format("[{0}][S]: {1}", player._alias, pkt.message)); } break; case Helpers.Chat_Type.EnemyTeam: //Send it to the players team and enemy's team player._team.playerTeamChat(player, pkt); if (!Allowed) { break; } if ((player._arena._specQuiet || player._specQuiet) && player.PermissionLevelLocal < Data.PlayerPermission.ArenaMod && player.IsSpectator) { break; } if (!pkt.recipient.Equals(player._alias, StringComparison.OrdinalIgnoreCase)) { Player recipient = player._arena.getPlayerByName(pkt.recipient); if (recipient != null) { pkt.message = String.Format("[Enemy] {0}", pkt.message); recipient._team.playerTeamChat(player, pkt); } } break; case Helpers.Chat_Type.PrivateChat: if (!player._server.IsStandalone) { CS_PrivateChat <Data.Database> pchat = new CS_PrivateChat <Data.Database>(); pchat.chat = pkt.recipient; pchat.message = pkt.message; pchat.from = player._alias; player._server._db.send(pchat); } break; case Helpers.Chat_Type.Whisper: { // Redirect to IRC. if (pkt.recipient.StartsWith("[IRC]")) { var ircName = pkt.recipient.Replace("[IRC]", ""); player._server.ircClient.SendMessage( Meebey.SmartIrc4net.SendType.Message, ircName, String.Format("[{0}]: {1}", player._alias, pkt.message)); break; } //Find our recipient Player recipient = player._server.getPlayer(pkt.recipient); //For league and spec quiet toggles if ((recipient != null) && !recipient.IsSpectator) { if (!Allowed) { break; } if (player._arena._specQuiet || player._specQuiet) { if (player.PermissionLevelLocal < Data.PlayerPermission.ArenaMod && player.IsSpectator) { break; } } } //Are we connected to a database? if (!player._server.IsStandalone) { //Yeah, lets route it through the DB so we can pm globally! CS_Whisper <Data.Database> whisper = new CS_Whisper <Data.Database>(); whisper.bong = pkt.bong; whisper.recipient = pkt.recipient; whisper.message = pkt.message; whisper.from = player._alias; player._server._db.send(whisper); } else { //Send it to the target player if (recipient != null) { recipient.sendPlayerChat(player, pkt); } } } break; case Helpers.Chat_Type.Squad: //Since squads are only zone-wide, we don't need to route it to the database, //instead we route it to every player in every arena in the zone foreach (Arena a in player._server._arenas.Values) { foreach (Player p in a.Players) { if (p == player) { continue; } if (String.IsNullOrWhiteSpace(pkt.recipient)) { continue; } if (!p._squad.Equals(pkt.recipient, StringComparison.OrdinalIgnoreCase)) { continue; } if (!player._squad.Equals(p._squad, StringComparison.OrdinalIgnoreCase)) { continue; } p.sendPlayerChat(player, pkt); } } break; } } }