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); } }); }
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())); }
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); } }
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))); } }
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())); } } }
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(); }; }
void OnRequestInitPlayer(Notification note) { GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseInitPlayer, note.GetBytes())); }
public void RequestInitPlayer() { GameClientNetwork.Instance.SendRequest(PtMessagePackage.Build((int)C2SMessageId.RequestInitPlayer, new ByteBuffer().WriteInt64(GameClientData.SelfPlayer.Id).Getbuffer())); }
public void RequestEnterRoom(string name) { GameClientNetwork.Instance.SendRequest(PtMessagePackage.Build((int)C2SMessageId.RequestEnterRoom, new ByteBuffer().WriteInt64(GameClientData.SelfPlayer.Id).WriteString(name).Getbuffer())); }