Exemplo n.º 1
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();
        }
    }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
0
        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);*/
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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;
                        }
                    }
                }
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
    }
Exemplo n.º 12
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);
    }
Exemplo n.º 13
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());
    }
Exemplo n.º 14
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());
    }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
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);
    }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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();
 }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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();
        }
Exemplo n.º 22
0
        void HandleServerHopping(ServerPingHopperPacket packet)
        {
            ServerConnectionHeader gatewayHeader = (ServerConnectionHeader)IntrepidSerialize.TakeFromPool(PacketType.ServerConnectionHeader);

            gatewayHeader.connectionId = nextConnectionId;
            socket.Send(gatewayHeader);

            ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
            string name = Assembly.GetCallingAssembly().GetName().Name;

            hopper.Stamp(name + " received");
            Send(packet);
        }
Exemplo n.º 23
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);
    }
Exemplo n.º 24
0
    //TODO: Split this up, as it is doing 2 things:
    //Updating nearby entities
    //Updating the position
    public void UpdateNearbyEntities()
    {
        // TODO: Hysteresis
        // We'll need to have a way to look up an entity by its id
        nearbyEntitiesCount = SpatialPartitioning.GetEntitiesInRadius(ref nearbyEntities, Position);

        for (int i = 0; i < nearbyEntitiesCount; i++)
        {
            var entity = nearbyEntities[i];
            if (entity == this || entity == null)
            {
                continue;
            }

            // Assume we haven't seen this entity before
            int frameIdLastUpdated = NetworkConstants.BeforeStartOfGameFrameId;

            // If we have seen this entity before...
            if (trackedEntityIds.Contains(entity.EntityId))
            {
                // TODO : Store the actual last frame we updated them, but for the moment
                // we update them every frame, so we saw them last frame
                frameIdLastUpdated = Server.FrameID - 1;
            }

            entity.SendState(this, frameIdLastUpdated);

            trackedEntityIds.Remove(entity.EntityId);
        }

        // These have all now disappered
        foreach (var entityId in trackedEntityIds)
        {
            // Tell the client to remove that entity
            EntityDestroyPacket destroyPacket = (EntityDestroyPacket)IntrepidSerialize.TakeFromPool(PacketType.EntityDestroy);
            destroyPacket.entityId = entityId;
            Server.Send(destroyPacket, EntityId.SingleItemAsEnumerable());
        }

        // Create the new list of tracked entities
        trackedEntityIds.Clear();
        for (int i = 0; i < nearbyEntitiesCount; i++)
        {
            var entity = nearbyEntities[i];
            if (entity == this || entity == null)
            {
                continue;
            }
            trackedEntityIds.Add(entity.EntityId);
        }
    }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
    void OnTick()
    {
        if (positionalTracker.Passes(transform.position, transform.rotation) == true)
        {
            WorldEntityPacket packet = (WorldEntityPacket)IntrepidSerialize.TakeFromPool(PacketType.WorldEntity);

            packet.entityId = EntityId;
            packet.position.Set(transform.position);
            packet.rotation.Set(transform.rotation.eulerAngles);

            Client.Send(packet);
            positionalTracker.Set(transform.position, transform.rotation);
        }
    }
Exemplo n.º 27
0
    private void AttackRequestPacket(Combat_AttackRequest packet)
    {
        // TODO: Validate attack.
        Combat_AttackOriginate ao = (Combat_AttackOriginate)IntrepidSerialize.TakeFromPool(PacketType.Combat_AttackOriginate);

        ao.attackerId = EntityId;
        ao.frameId    = Server.FrameID;
        ao.abilityId  = packet.abilityId;
        ao.targetId   = packet.targetId;
        ao.position   = packet.position;

        // keep in mind threading things
        /*int nearbyPlayersCount = */ SpatialPartitioning.GetEntitiesInRadius(ref nearbyPlayers, Position);
        Server.Send(ao, nearbyPlayers.Select(e => e.EntityId));
    }
Exemplo n.º 28
0
        public void Login(string username, string password)
        {
            if (hasSentCredentials || IsLoggedIn)
            {
                return;
            }

            LoginCredentials loginCredentials = (LoginCredentials)IntrepidSerialize.TakeFromPool(PacketType.LoginCredentials);

            loginCredentials.playerName.Copy(username);
            loginCredentials.password.Copy(password);
            Send(loginCredentials);

            hasSentCredentials = true;
        }
Exemplo n.º 29
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);
                }
            }
        }
Exemplo n.º 30
0
        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);
                }
            }
        }