示例#1
0
        public void ProcessUnloggedIn(BasePacket packet)
        {
            var packetType = packet.PacketType;

            if (packetType == PacketType.LoginCredentials)
            {
                LoginCredentials lc = packet as LoginCredentials;

                //credentialsReceived = true;
                //SendInitData(this);
            }
            else if (packetType == PacketType.LoginClientReady)
            {
                LoginClientReady lc = packet as LoginClientReady;
                loginComplete = true;
                // signal game server that player has logged in.
                // Also, all other servers should be signalled. Once we have a real login server, then the gateway will not need to do any of this.
            }
            else if (packetType == PacketType.ClientGameInfoResponse)
            {
                ClientGameInfoResponse lc = packet as ClientGameInfoResponse;
                gameId = lc.GameId;
            }
            IntrepidSerialize.ReturnToPool(packet);
        }
示例#2
0
        public void ServiceLimboConnections()
        {
            foreach (PlayerConnectionState player in limboConnections)
            {
                if (player.HasNewData())
                {
                    List <BasePacket> packetList = player.RetrieveData();
                    foreach (BasePacket packet in packetList)
                    {
                        LoginCredentials lc = packet as LoginCredentials;
                        if (lc != null && loginServerSocket != null)
                        {
                            UserAccountRequest uar = IntrepidSerialize.TakeFromPool(PacketType.UserAccountRequest) as UserAccountRequest;
                            uar.connectionId = player.tempId;
                            uar.password.Copy(lc.password);
                            uar.product_name.Copy("hungry hippos"); // TODO, configure product name
                            uar.username.Copy(lc.playerName);

                            loginServerSocket.Send(uar);
                            break;
                        }
                    }
                    IntrepidSerialize.ReturnToPool(packetList);
                }
            }
        }
示例#3
0
        void PassOutgoingPacketsOntoClients()
        {
            Queue <SocketPacketPair> tempPackets;

            lock (containersLock)
            {
                tempPackets = containers.outgoingPackets;
                containers.outgoingPackets = new Queue <SocketPacketPair>();
            }

            lock (connectedLock)
            {
                foreach (var pair in tempPackets)
                {
                    BasePacket bp           = pair.packet;
                    int        connectionId = pair.connectionId;
                    int        gameId       = pair.gameId;

                    bool found = false;
                    foreach (var player in players)
                    {
                        if (player.connectionId == connectionId)
                        {
                            player.AddPacket(bp);
                            found = true;
                            break;// first to match
                        }
                    }
                    if (found == false)
                    {
                        IntrepidSerialize.ReturnToPool(bp);
                    }
                }
            }
        }
示例#4
0
        void MigratePendingPlayersToLoginServer()
        {
            if (extremeLogging == true)
            {
                Console.WriteLine("MigratePendingPlayersToLoginServer");
            }

            List <PlayerConnectionState> tempList;

            lock (connectedLock)
            {
                tempList = new List <PlayerConnectionState>(newPlayersAwaitingConfirmation);
            }

            foreach (var newPlayer in tempList)
            {
                var packet = newPlayer.RetrievePacket();
                if (packet == null)
                {
                    continue;
                }
                var clientIdPacket = packet as ClientIdPacket;
                if (clientIdPacket != null)
                {
                    newPlayer.gameId = clientIdPacket.Id;
                    newPlayer.versionAndHandshakeComplete = true;
                    loginServerProxy.HandleNewConnection(newPlayer);
                    IntrepidSerialize.ReturnToPool(packet);
                    continue;
                }

                // If we're here, it means the client sent the wrong packet, so disconnect them
                lock (connectedLock)
                {
                    newPlayersAwaitingConfirmation.Remove(newPlayer);
                }
                if (extremeLogging == true)
                {
                    Console.WriteLine("Expected ClientIdPacket, received " + packet.GetType());
                }
                // TODO: Send disconnect packet?
                newPlayer.Disconnect();

                IntrepidSerialize.ReturnToPool(packet);
            }

            lock (connectedLock)
            {
                for (int i = newPlayersAwaitingConfirmation.Count - 1; i >= 0; i--)
                {
                    var newPlayer = newPlayersAwaitingConfirmation[i];
                    if (newPlayer.versionAndHandshakeComplete == true)
                    {
                        newPlayersAwaitingConfirmation.RemoveAt(i);
                    }
                }
            }
        }
示例#5
0
            public void Clear()
            {
                // blobs should already be freed
                foreach (var blob in accumulator)
                {
                    IntrepidSerialize.ReturnToPool(blob);
                }

                accumulator = new List <DataBlob>();
            }
示例#6
0
 private void SignalPacketListeners(IEnumerable <BasePacket> packets)
 {
     foreach (var packet in packets)
     {
         if (packet is EntityPacket)
         {
             packetDispatcher.SignalListener((packet as EntityPacket).entityId, packet);
         }
         packetDispatcher.SignalListener(packet);
         IntrepidSerialize.ReturnToPool(packet);
     }
 }
示例#7
0
        void ProcessUnprocessedLoginServerResponses()
        {
            List <BasePacket> tempPacketList;

            lock (responsesLock)
            {
                tempPacketList = unprocessedLoginServerResponses;
                unprocessedLoginServerResponses = new List <BasePacket>();
            }

            foreach (BasePacket packet in tempPacketList)
            {
                UserAccountResponse uar = packet as UserAccountResponse;
                if (uar == null)
                {
                    IntrepidSerialize.ReturnToPool(packet);
                    continue;
                }

                //List<PlayerConnectionState> validConnections;
                // the pending users should be a tiny list
                PlayerConnectionState foundPlayer = null;
                int indexOfFoundPlayer            = -1;
                foreach (PlayerConnectionState player in limboConnections)
                {
                    indexOfFoundPlayer++;
                    if (player.tempId == uar.connectionId)
                    {
                        foundPlayer = player;
                        break;
                    }
                }
                if (foundPlayer != null)
                {
                    limboConnections.RemoveAt(indexOfFoundPlayer);
                    foundPlayer.finishedLoginSuccessfully = uar.isValidAccount;
                    if (uar.isValidAccount == false)
                    {
                        invalidPlayers.Add(foundPlayer);
                    }
                    else
                    {
                        loggedInPlayers.Add(foundPlayer);
                    }

                    OnNewPlayerLoggedIn?.Invoke(foundPlayer, uar.isValidAccount, uar.state);
                }
                IntrepidSerialize.ReturnToPool(uar);
            }
        }
示例#8
0
        void HandleNormalPackets(Queue <BasePacket> listOfPackets)
        {
            foreach (var packet in listOfPackets)
            {
                numPacketsReceived++;
                // normal processing
                EntityPacket ep = packet as EntityPacket;
                if (ep != null)
                {
                    //entityId = ep.entityId;
                    int tempEntityId = ep.entityId;
                    if (entityId == tempEntityId)
                    {
                        Console.Write("This entity packet updated {0}\n", tempEntityId);
                    }
                    else
                    {
                        Console.Write("Entity update packet {0}\n", tempEntityId);
                    }
                    entityId = tempEntityId;
                    continue;
                }
                KeepAlive ka = packet as KeepAlive;
                if (ka != null)
                {
                    KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                    socket.Send(kar);
                }

                if (packet is ServerPingHopperPacket)
                {
                    ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
                    hopper.Stamp("client end");
                    hopper.PrintList();
                }
                if (packet.PacketType == PacketType.DataBlob)
                {
                    HandleBlobData(packet as DataBlob);
                }
            }
            foreach (var packet in listOfPackets)
            {
                if (packet.PacketType != PacketType.DataBlob)// tyhese need special handling
                {
                    IntrepidSerialize.ReturnToPool(packet);
                }
            }
        }
示例#9
0
        private void Send(BasePacket packet, IEnumerable <ConnectedClient> clients)
        {
            List <SocketPacketPair> listOfPacketsToSend = new List <SocketPacketPair>();

            foreach (var client in clients)// this should be improved. I try to save the results and then do them all at once. Prevents locks.
            {
                BasePacket bp = IntrepidSerialize.ReplicatePacket(packet);
                listOfPacketsToSend.Add(new SocketPacketPair(client.SocketId, bp));
            }
            lock (containersLock)
            {
                foreach (var item in listOfPacketsToSend)
                {
                    containers.outgoingPackets.Enqueue(item);
                }
            }
            IntrepidSerialize.ReturnToPool(packet);
        }
示例#10
0
        public void ProcessLoggedIn(BasePacket packet)
        {
            var packetType = packet.PacketType;

            // add possible attack vectors to this list
            // these cannot be processed once we are logged in.
            if (packetType == PacketType.LoginCredentials ||
                packetType == PacketType.LoginClientReady ||
                packetType == PacketType.ClientGameInfoResponse
                )
            {
                IntrepidSerialize.ReturnToPool(packet);
                return;
            }
            if (packetType == PacketType.ServerPingHopper)
            {
                string name = Assembly.GetCallingAssembly().GetName().Name;
                (packet as ServerPingHopperPacket).Stamp(name + " received from client");
            }
            Gateway.AddIncomingPacket(packet, connectionId, gameId);
        }
        public override void Send(BasePacket packet)
        {
            ServerConnectionHeader sch = packet as ServerConnectionHeader;

            if (sch != null)
            {
                nextConnectionId = sch.connectionId;
            }

            /*  if (packet.PacketType == PacketType.DataBlob)
             *  {
             *      if(accumulator.Add(packet as DataBlob) == true)
             *      {
             *          byte[] bytes = accumulator.ConvertDatablobsIntoRawData();
             *          validateReceivedBuffer(bytes);
             *          accumulator.Clear();
             *      }
             *      return;
             *  }*/



            if (packet.PacketType == PacketType.RequestPacket)
            {
                // Set camera position on renderer and rotation
                // call to Michaelangelo

                // requestedRenderFrame
                PlayerState ps = GetPlayerState(nextConnectionId);
                if (ps != null)
                {
                    ps.requestedRenderFrame = true;
                }
            }

            HandlePlayerPackets(packet);
            IntrepidSerialize.ReturnToPool(packet);
        }
示例#12
0
        private void Send()
        {
            BasePacket[] packetList = PrepPacketsToSend();
            if (packetList == null)
            {
                return;
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            for (int i = 0; i < packetList.Length; i++)
            {
                BasePacket packet = packetList[i];

                ManageDebuggingPackets(packet);

                int pos = Network.Utils.SetupWrite(binaryWriter);
                packet.Write(binaryWriter);
                Network.Utils.FinishWrite(binaryWriter, pos);

                IntrepidSerialize.ReturnToPool(packet);
            }
            SendRecursive(packetList);
        }
示例#13
0
        void HandleNormalPackets(Queue <BasePacket> listOfPackets)
        {
            foreach (var packet in listOfPackets)
            {
                //Console.WriteLine("normal packet received {0} .. isLoggedIn = true", packet.PacketType);
                numPacketsReceived++;
                // normal processing
                if (packet is PlayerFullPacket && localPlayer.entityId == 0)
                {
                    localPlayer.entityId = (packet as PlayerFullPacket).entityId;
                }

                /*     ServerTick st = packet as ServerTick;
                 *   if(st != null)
                 *   {
                 *       Console.WriteLine("server tick {0}", st.TickCount);
                 *
                 *       continue;
                 *   }*/
                KeepAlive ka = packet as KeepAlive;
                if (ka != null)
                {
                    KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                    socket.Send(kar);
                }

                if (packet is ServerPingHopperPacket)
                {
                    ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
                    hopper.Stamp("client end");
                    hopper.PrintList();
                }
                if (packet is WorldEntityPacket)
                {
                    WorldEntityPacket wep = packet as WorldEntityPacket;
                    if (localPlayer.entityId == wep.entityId)
                    {
                        localPlayer.position = wep.position.Get();
                        localPlayer.rotation = wep.rotation.Get();
                    }
                }
                EntityPacket ep = packet as EntityPacket;
                if (ep != null)
                {
                    //entityId = ep.entityId;
                    int tempEntityId = ep.entityId;
                    if (localPlayer.entityId == tempEntityId)
                    {
                        Console.Write("This entity packet updated {0}\n", tempEntityId);
                    }

                    /* else
                     * {
                     *   Console.Write("Entity update packet {0}\n", tempEntityId);
                     * }*/
                    continue;
                }

                // Console.WriteLine("normal packet received {0}", packet.PacketType);

                IntrepidSerialize.ReturnToPool(packet);
            }
        }
示例#14
0
        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);
                            }
                        }
                    }
                }
            }
        }