protected override void OnDisconnected() { base.OnDisconnected(); GatewayGlobal.Clients.Remove(ClientID); if (PlayerID != 0) { ClientDisconnectPacket pkg = new ClientDisconnectPacket(PlayerID); pkg.ClientID = ClientID; LogicServer.SendTCP(pkg); pkg = new ClientDisconnectPacket(PlayerID); pkg.ClientID = ClientID; GatewayGlobal.Send2Center(pkg, this); } if (Player != null) { Player.OnDisconnect(); } }
private void ProcessInputPacket(Packet packet) { if (packet is ClientInfoRequestPacket) { ClientInfoResponsePacket clientInfoResponse = new ClientInfoResponsePacket(sAlias); client.Send(clientInfoResponse); } else if (packet is ChatPacket) { ChatPacket cp = packet as ChatPacket; CallChatMessageReceived(cp.message, cp.player); } else if (packet is ObjectResponsePacket) { ObjectResponsePacket corp = packet as ObjectResponsePacket; CallObjectRequestResponseReceived(corp.ID, corp.AssetName); } else if (packet is ObjectUpdatePacket) { ObjectUpdatePacket oup = packet as ObjectUpdatePacket; CallObjectUpdateReceived(oup.objectId, oup.assetName, oup.position, oup.orientation, oup.velocity); } else if (packet is ObjectActionPacket) { ObjectActionPacket oap = packet as ObjectActionPacket; CallObjectActionReceived(oap.objectId, oap.actionParameters); } else if (packet is ClientDisconnectPacket) { ClientDisconnectPacket cdp = packet as ClientDisconnectPacket; CallClientDisconnected(cdp.Alias); } }
private void ProcessInputPacket(Packet packet) { if (packet is ClientInfoRequestPacket) { Trace.WriteLine("Received ClientInfoRequest"); ClientInfoRequestPacket cir = packet as ClientInfoRequestPacket; ClientInfoResponsePacket clientInfoResponse = new ClientInfoResponsePacket(sAlias); client.Send(clientInfoResponse); CallClientInfoRequestReceived(cir.ID); } else if (packet is ChatPacket) { ChatPacket cp = packet as ChatPacket; CallChatMessageReceived(new ChatMessage(cp.message, cp.player)); } else if (packet is ObjectAddedPacket) { Trace.WriteLine("Received ObjectAdded"); ObjectAddedPacket corp = packet as ObjectAddedPacket; CallObjectRequestResponseReceived(corp.Owner, corp.ID, corp.AssetName); } else if (packet is ObjectUpdatePacket) { ObjectUpdatePacket oup = packet as ObjectUpdatePacket; CallObjectUpdateReceived(oup.objectId, oup.assetName, oup.position, oup.orientation, oup.velocity); } else if (packet is ObjectActionPacket) { ObjectActionPacket oap = packet as ObjectActionPacket; CallObjectActionReceived(oap.objectId, oap.actionParameters); } else if (packet is ClientDisconnectPacket) { ClientDisconnectPacket cdp = packet as ClientDisconnectPacket; CallOtherClientDisconnectedFromServer(cdp.id); } else if (packet is ClientConnectedPacket) { ClientConnectedPacket ccp = packet as ClientConnectedPacket; CallOtherClientConnectedToServer(ccp.ID, ccp.Alias); } else if (packet is ObjectAttributePacket) { ObjectAttributePacket oap = packet as ObjectAttributePacket; CallObjectAttributeReceived(oap); } else if (packet is ObjectDeletedPacket) { Trace.WriteLine("Received ObjectDelete"); ObjectDeletedPacket odp = packet as ObjectDeletedPacket; CallObjectDeleteReceived(odp); } }
void NotifyGameServerThatPlayerHasDisconnected(int clientConnectionId, int gameId, int accountId) { Console.WriteLine("Disconnect on gateway (2), connectionId: " + clientConnectionId); foreach (var server in servers) { if (server.serverType != ServerIdPacket.ServerType.Game || server.gameId == gameId) { ClientDisconnectPacket cdp = (ClientDisconnectPacket)IntrepidSerialize.TakeFromPool(PacketType.ClientDisconnect); cdp.connectionId = clientConnectionId; cdp.accountId = accountId; server.Send(cdp); } } }
void MoveServerPacketsIntoOutgoingClients() { if (extremeLogging == true) { Console.WriteLine("MoveServerPacketsIntoOutgoingClients"); } List <GatewayPlayer> tempPlayerList; lock (connectedLock) { tempPlayerList = new List <GatewayPlayer>(players); } foreach (var server in servers) { if (server.HasNewData() == true) { List <BasePacket> newData = server.RetrieveData(); numServerPackets += newData.Count; foreach (var packet in newData) { if (packet is ServerConnectionHeader) { currentConnectionIdForHeader = (packet as ServerConnectionHeader).connectionId; currentPlayerForHeader = FindPlayer(currentConnectionIdForHeader, tempPlayerList); if (currentPlayerForHeader == null) { ClientDisconnectPacket clientDisconnect = (ClientDisconnectPacket)IntrepidSerialize.TakeFromPool(PacketType.ClientDisconnect); clientDisconnect.connectionId = currentConnectionIdForHeader; Console.WriteLine("Disconnecting connectionId (1): " + clientDisconnect.connectionId); server.Send(clientDisconnect); server.skipNextPacket = true; } else { server.skipNextPacket = false; } IntrepidSerialize.ReturnToPool(packet); } else { if (currentPlayerForHeader != null) { if (packet.PacketType == PacketType.ServerPingHopper) { string name = Assembly.GetCallingAssembly().GetName().Name; (packet as ServerPingHopperPacket).Stamp(name + ": game to client"); } // copy packet currentPlayerForHeader.connection.Send(packet); //Reset state for next packet pair. currentPlayerForHeader = null; currentConnectionIdForHeader = 0; } else { if (!server.skipNextPacket) { Console.WriteLine("Received packet without ServerConnectionHeader packet: {0} from {1} with id {2}", packet, server.serverType, server.gameId); } else { server.skipNextPacket = false; } IntrepidSerialize.ReturnToPool(packet); } } } } } }