public void PullClientInfo(VirCli[] syncInfo) { if (syncInfo != null) { int len = syncInfo.Length; if (len <= 0) { return; } for (int i = 0; i < len; ++i) { VirCli sync = syncInfo[i]; VirtualClient client = null; ClientStatus status = (ClientStatus)Enum.ToObject(typeof(ClientStatus), sync.curStatus); bool found = ClientPool.TryGetValue(sync.ClientID, out client); if (found) { client.curStatus = status; } else { ClientPool[sync.ClientID] = new VirtualClient() { ClientID = sync.ClientID, curStatus = status, }; } } } }
public void OnHeartBeat(string clientID) { if (!string.IsNullOrEmpty(clientID)) { VirtualClient client = null; bool setOk = ClientPool.TryGetValue(clientID, out client); if (setOk) { client.HeartTick = stopwatch.ElapsedMilliseconds; } } }
public bool QuitJoin(JoinInfo joinin) { bool setOk = false; if (joinin != null) { VirtualClient client = null; setOk = ClientPool.TryGetValue(joinin.ClientID, out client); if (setOk) { CharactorPool.QuitRoom(joinin.Charactor); //申请写锁 readerWriterLock.EnterWriteLock(); ClientPool.Remove(joinin.ClientID); //释放写锁 readerWriterLock.ExitWriteLock(); ConnectedClientCount -= 1; if (client.curStatus.check(ClientStatus.Ready)) { ReadyClientCount -= 1; } if (client.curStatus.check(ClientStatus.UIReady)) { UIReadyClientCount -= 1; } //guard if (ConnectedClientCount < 0) { ConnectedClientCount = 0; } if (ReadyClientCount < 0) { ReadyClientCount = 0; } if (UIReadyClientCount < 0) { UIReadyClientCount = 0; } AsyncClient(); } } return(setOk); }
public bool NotReady(ReadyInfo notready) { bool setOk = false; if (notready != null) { VirtualClient client = null; setOk = ClientPool.TryGetValue(notready.ClientID, out client); if (setOk) { client.curStatus = client.curStatus.clear(ClientStatus.Ready); ReadyClientCount -= 1; AsyncClient(); } } return(setOk); }
public void AddJoin(JoinInfo joinin) { if (joinin != null) { if (ClientPool.ContainsKey(joinin.ClientID) == false) { ConnectedClientCount += 1; VirtualClient client = new VirtualClient(joinin); CharactorPool.JoinRoom(joinin.Charactor); //申请写锁 readerWriterLock.EnterWriteLock(); ClientPool.Add(joinin.ClientID, client); //释放写锁 readerWriterLock.ExitWriteLock(); AsyncClient(); } } }
public bool Ready(ReadyInfo ready) { bool setOk = false; if (ready != null) { VirtualClient client = null; setOk = ClientPool.TryGetValue(ready.ClientID, out client); if (setOk) { if (client.curStatus.anysame(ClientStatus.Ready) == false) { client.curStatus = client.curStatus.set(ClientStatus.Ready); ReadyClientCount += 1; AsyncClient(); } } } return(setOk); }
public bool UIReady(UIReadyInfo uiready) { bool setOk = false; if (uiready != null) { VirtualClient client = null; setOk = ClientPool.TryGetValue(uiready.ClientID, out client); if (setOk) { if (client.curStatus.check(ClientStatus.Ready)) { client.curStatus = client.curStatus.set(ClientStatus.UIReady); UIReadyClientCount += 1; } else { setOk = false; } } } return(setOk); }