private void Sock_OnConnect(IPacketSend sender) { if (gatewaySocket != sender) { return; } ServerIdPacket serverId = (ServerIdPacket)IntrepidSerialize.TakeFromPool(PacketType.ServerIdPacket); serverId.Type = ServerIdPacket.ServerType.Game; serverId.Id = applicationId; serverId.MapId = 1; sender.Send(serverId); }
private void Socket_OnPacketsReceived(IPacketSend socket, Queue <BasePacket> receivedPackets) { numPacketsReceived += receivedPackets.Count; // Look for a server id packet if we've only just connected if (!isBoundToGateway) { var packet = receivedPackets.Dequeue(); if (packet is ServerIdPacket) { ServerIdPacket id = packet as ServerIdPacket; if (id != null && id.Type == ServerIdPacket.ServerType.Gateway) { isBoundToGateway = true; OnConnect?.Invoke(); } } else { socket.Disconnect(); Console.Error.WriteLine("Unexpected packet type, disconnecting: {0}", packet.PacketType); return; } } // Look for a login credentials valid packet if we've tried to log in else if (!IsLoggedIn && hasSentCredentials) { var packet = receivedPackets.Dequeue(); if (packet is LoginCredentialValid) { HandleLoginCredentialsValidPacket(packet as LoginCredentialValid); } else { socket.Disconnect(); Console.Error.WriteLine("Unexpected packet type, disconnecting: {0}", packet.PacketType); return; } } lock (unprocessedPackets) { // Store the other packets for retrieval later unprocessedPackets.AddRange(receivedPackets); } }
//------------------------------------------------------------------ public LoginServerProxy(SocketWrapperSettings loginServerToConnectTo) { newConnections = new List <PlayerConnectionState>(); limboConnections = new List <PlayerConnectionState>(); loggedInPlayers = new List <PlayerConnectionState>(); invalidPlayers = new List <PlayerConnectionState>(); unprocessedLoginServerResponses = new List <BasePacket>(); isConnectedToRealLogin = loginServerToConnectTo != null; if (isConnectedToRealLogin == true) { loginServerSocket = new SocketWrapper(loginServerToConnectTo); loginServerSocket.OnPacketsReceived += LoginServerSocket_OnPacketsReceived; loginServerSocket.Connect(); } configuredSleep = NetworkConstants.LoginProxyFPS; }
public void ProcessReceiveBuffer(IPacketSend socket, Queue <BasePacket> deserializedPackets) { if (deserializedPackets.Count < 1) { return; } while (deserializedPackets.Count > 0) { BasePacket packet = deserializedPackets.Dequeue(); PacketType packetType = packet.PacketType; Console.WriteLine("packetType: {0}\n", packetType); if (packetType == PacketType.UserAccountResponse) { ReceiveLogin(packet as UserAccountResponse); } } return; }
private void Sock_OnPacketsReceived(IPacketSend arg1, Queue <BasePacket> listOfPackets) { // all of these boolean checks should be replaced by a Strategy if (isBoundToGateway == true) { if (isLoggedIn == true) { //HandleNormalPackets(listOfPackets); lock (receivedPackets) { foreach (var packet in listOfPackets) { receivedPackets.Enqueue(packet); } } } else { foreach (var packet in listOfPackets) { LoginCredentialValid lcr = packet as LoginCredentialValid; if (lcr != null) { LoginClientReady temp = (LoginClientReady)IntrepidSerialize.TakeFromPool(PacketType.LoginClientReady); Send(temp); ClientGameInfoResponse cgir = (ClientGameInfoResponse)IntrepidSerialize.TakeFromPool(PacketType.ClientGameInfoResponse); cgir.GameId = (int)applicationId; Send(cgir); isLoggedIn = lcr.isValid; } if (entityId == 0)// until we are assigned an entity id, we can't do much { EntityPacket ep = packet as EntityPacket; if (ep != null) { entityId = ep.entityId; } } numPacketsReceived++; } } } else { foreach (var packet in listOfPackets) { numPacketsReceived++; if (packet is ServerIdPacket) { ServerIdPacket id = packet as ServerIdPacket; if (id != null && id.Type == ServerIdPacket.ServerType.Gateway) { isBoundToGateway = true; break; } } } } }
protected override void Socket_OnPacketsReceived(IPacketSend externalSocket, Queue <BasePacket> packets) { if (packets.Count == 1) { } }
private void Sock_OnPacketsReceived(IPacketSend arg1, Queue <BasePacket> listOfPackets) { // all of these boolean checks should be replaced by a Strategy if (isBoundToGateway == true) { foreach (var packet in listOfPackets) { numPacketsReceived++; // normal processing KeepAlive ka = packet as KeepAlive; if (ka != null) { KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse); socket.Send(kar); continue; } WorldEntityPacket wep = packet as WorldEntityPacket; if (wep != null) { foreach (var playerId in playerIds) { if (playerId.entityId == wep.entityId) { playerId.position = wep.position.Get(); playerId.rotation = wep.rotation.Get(); SendAllEntityPositions(); } } continue; } ServerConnectionHeader sch = packet as ServerConnectionHeader; if (sch != null) { nextConnectionId = sch.connectionId; continue; } PlayerSaveStatePacket pss = packet as PlayerSaveStatePacket; if (pss != null) { HandlePlayerSaveState(pss); continue; } if (packet is ServerPingHopperPacket) { HandleServerHopping(packet as ServerPingHopperPacket); continue; } } } else { foreach (var packet in listOfPackets) { numPacketsReceived++; if (packet is ServerIdPacket) { ServerIdPacket id = packet as ServerIdPacket; if (id != null && id.Type == ServerIdPacket.ServerType.Gateway) { isBoundToGateway = true; break; } } } } }
private void Sock_OnPacketsReceived(IPacketSend arg1, Queue <BasePacket> listOfPackets) { CurrentPacketHandling.HandlePackets(listOfPackets); }