Beispiel #1
0
 void StartRollingSyncMsgThread()
 {
     QueueKeyFrameCollection = new ConcurrentQueue <PtKeyFrameCollection>();
     ThreadPool.QueueUserWorkItem((state) =>
     {
         while (true)
         {
             DictKeyFrames.Clear();
             PtKeyFrameCollection collection = null;
             while (QueueKeyFrameCollection.TryDequeue(out collection))
             {
                 if (!DictKeyFrames.ContainsKey(collection.FrameIdx))
                 {
                     DictKeyFrames[collection.FrameIdx] = collection;
                 }
                 else
                 {
                     DictKeyFrames[collection.FrameIdx].AddKeyFramesRange(collection);
                 }
             }
             foreach (var value in DictKeyFrames.Values)
             {
                 GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseSyncKeyframes, false, PtKeyFrameCollection.Write(value)));
             }
             Thread.Sleep(40);
         }
     });
 }
Beispiel #2
0
 public void RequestSyncClientKeyframes(int frameIdx, PtKeyFrameCollection keyframes)
 {
     keyframes.FrameIdx = frameIdx;
     GameClientNetwork.Instance.SendRequest(PtMessagePackage.Build((int)C2SMessageId.RequestSyncClientKeyframes,
                                                                   new ByteBuffer().WriteBytes(PtKeyFrameCollection.Write(keyframes))
                                                                   .Getbuffer()));
 }
Beispiel #3
0
        void OnRequestEnterRoom(Notification note)
        {
            Message msg = note.GetMessage();

            using (ByteBuffer buff = new ByteBuffer(note.GetBytes()))
            {
                long   roleId = buff.ReadInt64();
                string name   = buff.ReadString();
                int    state  = GameServerData.EnterGameRoom(roleId, name);
                msg.Reply(PtMessagePackage.Build((int)S2CMessageId.ResponseEnterRoom,
                                                 new ByteBuffer().WriteInt32(state).WriteBytes(GameRoomSvo.Write(GameServerData.GameRoom)).Getbuffer()));
                //Debug.Log("[server] OnRequestEnterRoom !" + roleId);
            }
        }
Beispiel #4
0
        internal void FlushKeyFrame(int currentFrameIdx)
        {
            //StartRollingSyncMsgThread();

            PtKeyFrameCollection collection = null;

            while (QueueKeyFrameCollection.TryDequeue(out collection))
            {
                collection.FrameIdx = currentFrameIdx;
                collection.KeyFrames.ForEach((e) =>
                {
                    e.Idx = currentFrameIdx;
                });
                GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseSyncKeyframes, true, PtKeyFrameCollection.Write(collection)));
            }
        }
Beispiel #5
0
        void OnRequestPlayerReady(Notification note)
        {
            Message msg = note.GetMessage();

            using (ByteBuffer buff = new ByteBuffer(note.GetBytes()))
            {
                long roleId = buff.ReadLong();
                GameServerData.SetGameMemeberReady(roleId);
                GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponsePlayerReady, buff.Getbuffer()));

                if (GameServerData.IsAllReadyInGameRoom())
                {
                    ByteBuffer buffer = new ByteBuffer();
                    buffer.WriteInt32(GameServerData.GameRoom.Members.Count);
                    foreach (var mem in GameServerData.GameRoom.Members)
                    {
                        buffer.WriteLong(mem.Id);
                    }
                    GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseAllPlayerReady, buffer.Getbuffer()));
                }
            }
        }
Beispiel #6
0
    public void Start()
    {
        m_Server = new Server();
        m_Server.Start(IPAddress.Parse("192.168.18.56"), 10000);

        m_Server.ClientConnected += (send, msg) =>
        {
            var player = GameServerData.AddNewPlayer();
            PtMessagePackage package = PtMessagePackage.Build((int)S2CMessageId.ResponseClientConnected, new ByteBuffer().WriteLong(player.Id).Getbuffer());
            byte[]           byts    = PtMessagePackage.Write(package);
            NetworkStreamUtil.Write(msg.GetStream(), byts);
        };

        m_Server.ClientDisconnected += (send, msg) =>
        {
            UnityEngine.Debug.Log("ClientDisconnected" + msg.ToString());
        };

        m_Server.DataReceived += (send, msg) =>
        {
            m_QueueMsg.Enqueue(msg);
            TickDispatchMessages();
        };
    }
Beispiel #7
0
 void OnRequestInitPlayer(Notification note)
 {
     GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseInitPlayer, note.GetBytes()));
 }
Beispiel #8
0
 public void RequestInitPlayer()
 {
     GameClientNetwork.Instance.SendRequest(PtMessagePackage.Build((int)C2SMessageId.RequestInitPlayer,
                                                                   new ByteBuffer().WriteInt64(GameClientData.SelfPlayer.Id).Getbuffer()));
 }
Beispiel #9
0
 public void RequestEnterRoom(string name)
 {
     GameClientNetwork.Instance.SendRequest(PtMessagePackage.Build((int)C2SMessageId.RequestEnterRoom,
                                                                   new ByteBuffer().WriteInt64(GameClientData.SelfPlayer.Id).WriteString(name).Getbuffer()));
 }