Example #1
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);
        }
        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);*/
        }
Example #3
0
    void SaveStatePacket(PlayerSaveStatePacket packet)
    {
        Debug.Log("RECEIVED!");
        trackedEntityIds = new HashSet <int>();
        AccountId        = packet.state.accountId;
        this.saveState   = packet.state;

        SpatialPartitioning.Register(this);
    }
Example #4
0
    public void SendPlayerSaveState(string defaultSaveState, PlayerSaveState stateFromServer)
    {
        PlayerSaveStatePacket packet = (PlayerSaveStatePacket)IntrepidSerialize.TakeFromPool(PacketType.PlayerSaveState);

        saveState = stateFromServer;

        packet.state = saveState;
        if (!saveState.hasState())
        {
            // the player doesn't exist yet
            // so load the default state
            packet.state.name        = "Player" + packet.state.accountId;
            packet.state.state.state = defaultSaveState;
        }

        Server.Send(packet, this.EntityId.SingleItemAsEnumerable());
    }
Example #5
0
    // GameClientComponent will wire this up to the IClientInterface.OnPlayerStateSaveReceived event.
    // We assume that Load will have been called already by the time this is fired.
    private void StateLoaded(PlayerSaveStatePacket packet)
    {
        string state = packet.state.state.state;
        // We need to capture the lastLoadSaveName before we null it out
        // so that the closures below work
        string saveName = lastLoadSaveName;

        try
        {
            JObject saveData = JObject.Parse(state);
            OnLoadCompleted?.Invoke(this, new GameStateStoreLoadResult(saveName, true, saveData));
        }
        catch (Exception)
        {
            OnLoadCompleted?.Invoke(this, new GameStateStoreLoadResult(saveName, false, null));
        }
        finally
        {
            lastLoadSaveName = null;
        }
    }
Example #6
0
            public override void HandlePackets(Queue <BasePacket> listOfPackets)
            {
                server.numPacketsReceived += listOfPackets.Count;
                foreach (var packet in listOfPackets)
                {
                    // normal processing
                    ServerConnectionHeader sch = packet as ServerConnectionHeader;// should be converted to a wrapper
                    if (sch != null)
                    {
                        server.NextConnectionId = sch.connectionId;
                        continue;
                    }
                    PlayerSaveStatePacket pss = packet as PlayerSaveStatePacket;
                    if (pss != null)
                    {
                        server.LogInPlayer(server.NextConnectionId, pss.state);

                        // send all entities in area to player eventually.
                        // notify all other players that this player is here.
                        continue;
                    }

                    //--------------------------------------------
                    KeepAlive ka = packet as KeepAlive;
                    if (ka != null)
                    {
                        KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                        //gatewaySocket.Send(kar);
                        server.AddOutgoingPacket(kar, ServerNetworking.InvalidConnectionId);
                        continue;
                    }

                    if (server.connectedClients.ContainsKey(server.NextConnectionId))
                    {
                        server.connectedClients[server.NextConnectionId].AddIncomingPacket(packet);
                    }
                }
            }
        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;
                        }
                    }
                }
            }
        }