示例#1
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);
                    }
                }
            }
        }
示例#2
0
            public List <DataBlob> PrepToSendRawData(byte[] rawData, int size)
            {
                List <DataBlob> blobs  = new List <DataBlob>();
                int             offset = 0;
                int             index  = 0;

                while (offset < size)
                {
                    DataBlob blob = (DataBlob)IntrepidSerialize.CreatePacket(PacketType.DataBlob);
                    blob.totalRawDataPacketCount = 1;
                    blob.packetIndex             = (short)index++;
                    int currentSize = size - offset;
                    if (currentSize > NetworkConstants.DataBlobMaxPacketSize)
                    {
                        currentSize = NetworkConstants.DataBlobMaxPacketSize;
                    }
                    //if(currentSize > size - offset)

                    blob.Prep(rawData, currentSize, offset);
                    offset += currentSize;
                    blobs.Add(blob);
                }
                foreach (var blob in blobs)
                {
                    blob.totalRawDataPacketCount = (short)index;
                }
                return(blobs);
            }
示例#3
0
        //------------------------------------------------------------------------------

        #region MARSHALLING_PACKETS
        void PassSaveStateToGameServer(int gameId, int connectionId, PlayerSaveState save)
        {
            PlayerSaveStatePacket player = (PlayerSaveStatePacket)IntrepidSerialize.TakeFromPool(PacketType.PlayerSaveState);

            player.state = save;
            AddIncomingPacket(player, connectionId, gameId);
        }
示例#4
0
    private void SendDirtyMemoryVar(ServerPlayer[] playerInRange)
    {
        if (playerInRange.Length > 0)
        {
            NPC_BlackBoard packet = IntrepidSerialize.TakeFromPool(PacketType.NPC_BlackBoard) as NPC_BlackBoard;

            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter bw           = new BinaryWriter(memoryStream);

            bw.Write(dirtyVars.Count);


            for (int i = 0; i < dirtyVars.Count; i++)
            {
                BBWriterReader.Write(dirtyVars[i], bw);
            }

            packet.bbDelta = memoryStream.ToArray();

            packet.entityId = EntityId;

            Server.Send(packet, playerInRange.Select(e => e.EntityId));

            dirtyVars.Clear();
        }
    }
示例#5
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);
        }
        void HandlePlayerSaveState(PlayerSaveStatePacket pss)
        {
            // send all entities in area to player eventually.
            // notify all other players that this player is here.
            PlayerState ps = new PlayerState();

            ps.connectionId = nextConnectionId;
            ps.accountId    = pss.state.accountId;
            ps.characterId  = pss.state.characterId;
            ps.entityId     = GetNewUserId();
            playerIds.Add(ps);

            ServerConnectionHeader gatewayHeader = (ServerConnectionHeader)IntrepidSerialize.TakeFromPool(PacketType.ServerConnectionHeader);

            gatewayHeader.connectionId = ps.connectionId;
            EntityPacket entityNotification = (EntityPacket)IntrepidSerialize.TakeFromPool(PacketType.Entity);

            entityNotification.entityId = ps.entityId;

            deserializedPackets.Add(gatewayHeader);
            deserializedPackets.Add(entityNotification);

            /* socket.Send(gatewayHeader);
             *  socket.Send(entityNotification);*/
        }
示例#7
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);
                }
            }
        }
示例#8
0
        private void Socket_OnConnect(IPacketSend socket)
        {
            // Tell the gateway who we are
            ClientIdPacket clientId = (ClientIdPacket)IntrepidSerialize.TakeFromPool(PacketType.ClientIdPacket);

            clientId.Id = ApplicationId;
            Send(clientId);
        }
示例#9
0
 override public void Dispose()
 {
     if (rawData != null)
     {
         IntrepidSerialize.ReturnBufferToPool(rawData);
     }
     rawData = null;// cleanup
 }
示例#10
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);
                    }
                }
            }
        }
示例#11
0
        public void SendUpdateCharacter(int characterId, PlayerSaveStateData state)
        {
            Console.WriteLine("send update char: characterId: {0}, state: {1}", characterId, state);
            ProfileUpdateCharacter packet = (ProfileUpdateCharacter)IntrepidSerialize.TakeFromPool(PacketType.ProfileUpdateCharacter);

            packet.characterId = characterId;
            packet.state       = state;
            socket.Send(packet);
        }
示例#12
0
        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);
                }
                else
                {
                    foreach (var packet in listOfPackets)
                    {
                        Console.WriteLine("normal packet received {0} .. isLoggedIn = false", packet.PacketType);
                        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 (localPlayer.entityId == 0)// until we are assigned an entity id, we can't do much
                         *  {
                         *      EntityPacket ep = packet as EntityPacket;
                         *      if (ep != null)
                         *      {
                         *          localPlayer.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;
                        }
                    }
                }
            }
        }
示例#13
0
        void ManageDebuggingPackets(BasePacket packet)
        {
#if DEBUG_NETWORK_PACKETS
            if (IntrepidSerialize.DebugLogPacket(packet))
            {
                Console.WriteLine("Attempting to send {0}", packet);
            }
#endif
        }
示例#14
0
        public void SendPositionInfo()
        {
            WorldEntityPacket wep = (WorldEntityPacket)IntrepidSerialize.TakeFromPool(PacketType.WorldEntity);

            wep.rotation.Set(rotation);
            wep.position.Set(position);
            wep.entityId = entityId;
            testClient.Send(wep);
        }
示例#15
0
        private void NotifyEndpoint_ServerId(ConnectionState connection)
        {
            ServerIdPacket packet = (ServerIdPacket)IntrepidSerialize.TakeFromPool(PacketType.ServerIdPacket);

            packet.Type  = ServerIdPacket.ServerType.Gateway;
            packet.MapId = 0;
            packet.Id    = 0;
            connection.Send(packet);
        }
        public void ConnectMock()
        {
            ServerIdPacket serverId = (ServerIdPacket)IntrepidSerialize.TakeFromPool(PacketType.ServerIdPacket);

            serverId.Type  = ServerIdPacket.ServerType.Game;
            serverId.Id    = (int)1234;
            serverId.MapId = 1;
            deserializedPackets.Add(serverId);
            //controller.Send(serverId);
        }
示例#17
0
    public void Save(string saveName, JObject json)
    {
#if DEBUG_SAVES
        Debug.Log(json);
#endif
        UpdatePlayerSaveStatePacket packet = (UpdatePlayerSaveStatePacket)IntrepidSerialize.TakeFromPool(PacketType.UpdatePlayerSaveState);
        packet.state       = new PlayerSaveStateData();
        packet.state.state = json.ToString();
        GameClient.Instance.Client.Send(packet);
    }
示例#18
0
    public override void SendPositionAndRotationData(ServerPlayer destPlayer)
    {
        WorldEntityPacket liveEntityPosition = (WorldEntityPacket)IntrepidSerialize.TakeFromPool(PacketType.WorldEntity);

        liveEntityPosition.entityId = EntityId;
        liveEntityPosition.position.Set(Position);
        liveEntityPosition.rotation.Set(Rotation);

        Server.Send(liveEntityPosition, destPlayer.EntityId.SingleItemAsEnumerable());
    }
示例#19
0
        public void SendApplicationQuitMessage()
        {
            ServerDisconnectPacket sdp = (ServerDisconnectPacket)IntrepidSerialize.TakeFromPool(PacketType.ServerDisconnect);

            sdp.Type  = ServerIdPacket.ServerType.Game;
            sdp.Id    = applicationId;
            sdp.MapId = 1;
            // send immediately
            gatewaySocket.Send(sdp);
        }
示例#20
0
            public void Clear()
            {
                // blobs should already be freed
                foreach (var blob in accumulator)
                {
                    IntrepidSerialize.ReturnToPool(blob);
                }

                accumulator = new List <DataBlob>();
            }
示例#21
0
    public void RequestAttack(int abilityId, int targetId, Vector3 position)
    {
        Combat_AttackRequest packet = (Combat_AttackRequest)IntrepidSerialize.TakeFromPool(PacketType.Combat_AttackRequest);

        packet.frameId   = Client.FrameID;
        packet.abilityId = abilityId;
        packet.targetId  = targetId;
        packet.position  = position;
        Client.Send(packet);
    }
示例#22
0
    public virtual void SendPositionAndRotationData(ServerPlayer destPlayer)
    {
        WorldEntityPacket packet = (WorldEntityPacket)IntrepidSerialize.TakeFromPool(PacketType.WorldEntity);

        packet.entityId = EntityId;
        packet.position.Set(Position);
        packet.rotation.Set(Rotation);

        Server.Send(packet, destPlayer.EntityId.SingleItemAsEnumerable());
    }
示例#23
0
    public override void SendInitData(ServerPlayer destPlayer, EntityFullPacket packet = null)
    {
        PlayerFullPacket pfp = packet as PlayerFullPacket;

        if (pfp == null)
        {
            pfp = (PlayerFullPacket)IntrepidSerialize.TakeFromPool(PacketType.PlayerFull);
        }
        base.SendInitData(destPlayer, pfp);
    }
示例#24
0
        public void SendCreateCharacter(int accountId, string productName, string characterName, PlayerSaveStateData state)
        {
            Console.WriteLine("send create char: accountId: {0}, productName: {1}, charName: {2}, state: {3}", accountId, productName, characterName, state);
            ProfileCreateCharacterRequest packet = (ProfileCreateCharacterRequest)IntrepidSerialize.TakeFromPool(PacketType.ProfileCreateCharacterRequest);

            packet.accountId = accountId;
            packet.productName.Copy(productName);
            packet.characterName.Copy(characterName);
            packet.state = state;
            socket.Send(packet);
        }
示例#25
0
        public void SendLoginRequest(string username, string password, string productname)
        {
            Console.WriteLine("send request: username: {0}\npassword: {1}\nproductname: {2}\n", username, password, productname);
            UserAccountRequest loginCredentials = (UserAccountRequest)IntrepidSerialize.TakeFromPool(PacketType.UserAccountRequest);

            loginCredentials.password.Copy(password);
            loginCredentials.username.Copy(username);
            loginCredentials.connectionId = 0;
            loginCredentials.product_name.Copy(productname);
            socket.Send(loginCredentials);
        }
示例#26
0
 public override void SendInitData(ServerPlayer destPlayer, EntityFullPacket packet = null)
 {
     if (packet == null)
     {
         packet = (EntityFullPacket)IntrepidSerialize.TakeFromPool(PacketType.EntityFull);
     }
     packet.position.Set(Position);
     packet.rotation.Set(Rotation);
     base.SendInitData(destPlayer, packet);
     OnInitData?.Invoke();
 }
示例#27
0
        //------------------------------- events --------------------------
        private void Sock_OnConnect(IPacketSend sender)
        {
            if (socket != sender)
            {
                return;
            }

            ClientIdPacket clientId = (ClientIdPacket)IntrepidSerialize.TakeFromPool(PacketType.ClientIdPacket);

            clientId.Id = (int)applicationId;
            sender.Send(clientId);
        }
示例#28
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);
     }
 }
示例#29
0
        private static void Main(string[] args)
        {
            CommonLibrary.Parser.ParseCommandLine(args);
            long applicationId = CommonLibrary.Parser.ApplicationId;

            if (applicationId == 0)
            {
                applicationId = Network.Utils.GetIPBasedApplicationId();
            }
            float  sleepTime = 1000.0f / (float)CommonLibrary.Parser.FPS;
            string ipAddr    = CommonLibrary.Parser.ipAddr;

            Console.WriteLine("Game server talking to Gateway.");
            //Console.WriteLine("  Press L to login (auto login is set).");
            Console.WriteLine("  Press P to update player position.");
            Console.WriteLine("  ** application id = {0} **", applicationId);
            Console.WriteLine("  Press esc to update player position.\n\n");

            ushort port = 11004;
            TestGameServerController testServer = new TestGameServerController(ipAddr, port, applicationId);

            //testServer.Star
            //testServer.
            // open  socket to connect to the gateway
            // upon connect, send ServerIdPacket:Game to connected
            // receive ServerIdPacket:Gateway
            // upon disconnect, reconnect

            ConsoleKey key;

            do
            {
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(20);
                }
                key = Console.ReadKey(true).Key;

                if (key == ConsoleKey.P)
                {
                    WorldEntityPacket we = (WorldEntityPacket)IntrepidSerialize.TakeFromPool(PacketType.WorldEntity);
                    we.entityId = 1024;
                    we.position.Set(new Vector3(10, 20, 30));
                    we.rotation.Set(new Vector3(10, 20, 30));

                    testServer.Send(we);
                    Console.WriteLine("position sent.");
                }
            } while (key != ConsoleKey.Escape);

            testServer.Close();
        }
示例#30
0
    public override void SendInitData(ServerPlayer destPlayer, EntityFullPacket packet = null)
    {
        NPCFullPacket npcPacket = packet as NPCFullPacket;

        if (npcPacket == null)
        {
            npcPacket = (NPCFullPacket)IntrepidSerialize.TakeFromPool(PacketType.NPCFull);
        }
        npcPacket.AgentID  = agentID;
        npcPacket.ConfigID = configID;

        base.SendInitData(destPlayer, npcPacket);
    }