Esempio n. 1
0
        // TODO:
        //  player update messages:
        //  1. player list (for newcomer)
        //  2. new player (for other players)
        //  3. remove player (for other players)
        public void UpdatePlayers(Msg_SC_UpdatePlayers msg)
        {
            if (msg.Clear)
            {
                foreach (var p in mPlayers)
                {
                    p.Dispose();
                }
                mPlayers.Clear();
            }

            Protocol.Player playerData = InstancePool.Get <Protocol.Player>();
            for (int i = 0; i < msg.AddPlayersLength; ++i)
            {
                msg.GetAddPlayers(playerData, i);
                PlayerClient newPlayer = PlayerClient.New(playerData);
                mPlayers.Add(newPlayer);
            }

            for (int i = 0; i < msg.RemovePlayersLength; ++i)
            {
                PlayerClient removePlayer = Get(msg.GetRemovePlayers(i));
                if (null != removePlayer)
                {
                    removePlayer.Dispose();
                    mPlayers.Remove(removePlayer);
                }
            }
        }
Esempio n. 2
0
        MessageHandleResult LoginHandler(
            NetConnection connection,
            ByteBuffer byteBuffer,
            NetIncomingMessage message)
        {
            Msg_SC_Login msg = InstancePool.Get <Msg_SC_Login>();

            Msg_SC_Login.GetRootAsMsg_SC_Login(byteBuffer, msg);
            if (!msg.Success)
            {
                GameStateLog.Error("Login failed:" + msg.Error);
                TransitTo <Error>(msg.Error);
            }
            else
            {
                game.id = msg.Id;
                GameStateLog.Info("Login success, game id:" + msg.Id);

                Msg_SC_UpdatePlayers updateplayers = InstancePool.Get <Msg_SC_UpdatePlayers>();
                msg.GetPlayers(updateplayers);
                PlayerManagerClient.Instance.UpdatePlayers(updateplayers);
                GameStateLog.Info("Update players");

                TransitTo <DataFullUpdate>();
            }
            return(MessageHandleResult.Finished);
        }
Esempio n. 3
0
        MessageHandleResult UpdatePlayersHandler(
            NetConnection connection,
            ByteBuffer byteBuffer,
            NetIncomingMessage message)
        {
            Msg_SC_UpdatePlayers updateplayers = InstancePool.Get <Msg_SC_UpdatePlayers>();

            Msg_SC_UpdatePlayers.GetRootAsMsg_SC_UpdatePlayers(byteBuffer, updateplayers);
            UpdatePlayers(updateplayers);
            return(MessageHandleResult.Finished);
        }
        Offset <Msg_SC_UpdatePlayers> SyncNewPlayer(FlatBufferBuilder fbb, int id)
        {
            VectorOffset pvOffset = default(VectorOffset);
            Player       p        = Get(id);

            if (null != p)
            {
                var array  = OffsetArrayPool.Alloc <Protocol.Player>(1);
                var offset = Protocol.Player.CreatePlayer(fbb, p.id, fbb.CreateString(p.playerName));
                array.offsets[array.position++] = offset;
                Msg_SC_UpdatePlayers.StartAddPlayersVector(fbb, array.position);
                pvOffset = Helpers.SetVector(fbb, array);
                OffsetArrayPool.Dealloc(ref array);
            }
            return(Msg_SC_UpdatePlayers.CreateMsg_SC_UpdatePlayers(fbb, false, pvOffset));
        }
        Offset <Msg_SC_UpdatePlayers> SyncPlayerList(FlatBufferBuilder fbb)
        {
            VectorOffset pvOffset = default(VectorOffset);

            if (mPlayers.Count > 0)
            {
                var array = OffsetArrayPool.Alloc <Protocol.Player>(mPlayers.Count);
                foreach (var p in mPlayers)
                {
                    var offset = Protocol.Player.CreatePlayer(fbb, p.id, fbb.CreateString(p.playerName));
                    array.offsets[array.position++] = offset;
                }
                Msg_SC_UpdatePlayers.StartAddPlayersVector(fbb, array.position);
                pvOffset = Helpers.SetVector(fbb, array);
                OffsetArrayPool.Dealloc(ref array);
            }
            return(Msg_SC_UpdatePlayers.CreateMsg_SC_UpdatePlayers(fbb, true, pvOffset));
        }