/// <summary> /// Removes a player from the database chat list /// </summary> public void lostPlayer(Zone.Player player) { if (!_players.Remove(player)) { Log.write(TLog.Warning, "Lost player '{0}' that wasn't in chat '{1}'.", player, _name); return; } SC_LeaveChat <Zone> leave = new SC_LeaveChat <Zone>(); leave.from = player.alias; leave.chat = _name; leave.users = List(); foreach (Zone z in _server._zones) { if (z == null) { continue; } z._client.send(leave); } //Do we still have a raison d'etre? if (_players.Count() == 0) { //Abandon ourselves to die if (!_server._chats.Remove(_name)) { Log.write(TLog.Error, "Attempted to remove chat '{0}' not present in chats list.", _name); return; } } }
static public void Handle_SC_LeaveChat(SC_LeaveChat <Database> pkt, Database _db) { string[] splitArr = { ", " }; List <string> users = new List <string>(); users = pkt.users.Split(splitArr, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList(); SC_Chat notify = new SC_Chat(); notify.chatType = Helpers.Chat_Type.PrivateChat; notify.message = pkt.chat + ":<< Leaving Chat >>"; notify.from = pkt.from; foreach (string user in users) { Player p = _db._server.getPlayer(user); if (p == null) { continue; } if (p._alias == pkt.from) { continue; } p._client.send(notify); } }
/// <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 SC_Auth <T> .TypeID: packet = new SC_Auth <T>(typeID, buffer, offset, size); break; case SC_PlayerLogin <T> .TypeID: packet = new SC_PlayerLogin <T>(typeID, buffer, offset, size); break; case SC_PlayerStatsResponse <T> .TypeID: packet = new SC_PlayerStatsResponse <T>(typeID, buffer, offset, size); break; case SC_Whisper <T> .TypeID: packet = new SC_Whisper <T>(typeID, buffer, offset, size); break; case SC_JoinChat <T> .TypeID: packet = new SC_JoinChat <T>(typeID, buffer, offset, size); break; case SC_LeaveChat <T> .TypeID: packet = new SC_LeaveChat <T>(typeID, buffer, offset, size); break; case SC_PrivateChat <T> .TypeID: packet = new SC_PrivateChat <T>(typeID, buffer, offset, size); break; case SC_Chat <T> .TypeID: packet = new SC_Chat <T>(typeID, buffer, offset, size); break; case SC_Zones <T> .TypeID: packet = new SC_Zones <T>(typeID, buffer, offset, size); break; case Disconnect <T> .TypeID: packet = new Disconnect <T>(typeID, buffer, offset, size); break; default: //An undefined packet. packet = new PacketDummy(typeID, buffer, offset, size); break; } return(packet); }