/// <summary> /// Declares that a player has left the server /// </summary> public void lostPlayer(Player player) { //Notify the database! CS_PlayerLeave <Database> pkt = new CS_PlayerLeave <Database>(); pkt.player = player.toInstance(); pkt.alias = player._alias; send(pkt); }
/// <summary> /// Handles a player leave notification /// </summary> static public void Handle_CS_PlayerLeave(CS_PlayerLeave <Zone> pkt, Zone zone) { //He's gone! if (zone == null) { Log.write(TLog.Error, "Handle_CS_PlayerLeave(): Called with null zone."); return; } if (string.IsNullOrWhiteSpace(pkt.alias)) { Log.write(TLog.Warning, "Handle_CS_PlayerLeave(): No alias provided."); } Zone.Player p = zone.getPlayer(pkt.alias); if (p == null) { Log.write(TLog.Warning, "Handle_CS_PlayerLeave(): Player '{0}' not found by alias.", pkt.alias); //Don't return until I have a better grasp of this } //Remove the player from the zone zone.lostPlayer(pkt.player.id); Log.write("Player '{0}' left zone '{1}'", pkt.alias, zone._zone.name); // Update their playtime using (InfantryDataContext db = zone._server.getContext()) { Data.DB.alias alias = db.alias.SingleOrDefault(a => a.name.Equals(pkt.alias)); //Data.DB.alias alias = db.alias.SingleOrDefault(a => a.id == p.aliasid); //If person was loaded correctly, save their info if (alias != null) { TimeSpan ts = DateTime.Now - alias.lastAccess; Int64 minutes = ts.Minutes; alias.timeplayed += minutes; db.SubmitChanges(); } } }
/// <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); }