internal void Update() { lock (noLoginList) { tick++; for (int i = noLoginList.Count - 1; i > -1; i--) { ServerUnit <T> serverUnit = noLoginList[i]; int uid = serverUnit.CheckLogin(tick); if (uid == -1) { noLoginList.RemoveAt(i); } else if (uid > 0) { Console.WriteLine("One user login uid:" + uid); noLoginList.RemoveAt(i); if (loginDic.ContainsKey(uid)) { ServerUnit <T> oldServerUnit = loginDic[uid]; oldServerUnit.Kick(); serverUnit.SetUnit(oldServerUnit.unit); loginDic[uid] = serverUnit; } else if (logoutDic.ContainsKey(uid)) { T unit = logoutDic[uid]; logoutDic.Remove(uid); serverUnit.SetUnit(unit); loginDic.Add(uid, serverUnit); } else { T unit = new T(); serverUnit.SetUnit(unit); loginDic.Add(uid, serverUnit); } } } } List <KeyValuePair <int, ServerUnit <T> > > kickList = null; Dictionary <int, ServerUnit <T> > .Enumerator enumerator = loginDic.GetEnumerator(); while (enumerator.MoveNext()) { bool kick = enumerator.Current.Value.Update(tick); if (kick) { if (kickList == null) { kickList = new List <KeyValuePair <int, ServerUnit <T> > >(); } kickList.Add(enumerator.Current); } } if (kickList != null) { for (int i = 0; i < kickList.Count; i++) { KeyValuePair <int, ServerUnit <T> > pair = kickList[i]; loginDic.Remove(pair.Key); logoutDic.Add(pair.Key, pair.Value.unit); } } }
internal void Update() { lock (locker) { tick++; LinkedListNode <ServerUnit <T> > node = noLoginList.First; while (node != null) { LinkedListNode <ServerUnit <T> > nextNode = node.Next; ServerUnit <T> serverUnit = node.Value; int uid = serverUnit.CheckLogin(tick); if (uid == -1) { noLoginList.Remove(node); } else if (uid > 0) { Console.WriteLine("One user login uid:" + uid); noLoginList.Remove(node); if (loginDic.ContainsKey(uid)) { ServerUnit <T> oldServerUnit = loginDic[uid]; oldServerUnit.Kick(); serverUnit.SetUnit(oldServerUnit.unit); loginDic[uid] = serverUnit; } else if (logoutDic.ContainsKey(uid)) { T unit = logoutDic[uid]; logoutDic.Remove(uid); serverUnit.SetUnit(unit); loginDic.Add(uid, serverUnit); } else { T unit = new T(); serverUnit.SetUnit(unit); loginDic.Add(uid, serverUnit); } } node = nextNode; } LinkedList <KeyValuePair <int, ServerUnit <T> > > kickList = null; Dictionary <int, ServerUnit <T> > .Enumerator enumerator = loginDic.GetEnumerator(); while (enumerator.MoveNext()) { bool kick = enumerator.Current.Value.Update(tick); if (kick) { if (kickList == null) { kickList = new LinkedList <KeyValuePair <int, ServerUnit <T> > >(); } kickList.AddLast(enumerator.Current); } } if (kickList != null) { LinkedList <KeyValuePair <int, ServerUnit <T> > > .Enumerator enumerator2 = kickList.GetEnumerator(); while (enumerator2.MoveNext()) { KeyValuePair <int, ServerUnit <T> > pair = enumerator2.Current; loginDic.Remove(pair.Key); logoutDic.Add(pair.Key, pair.Value.unit); unitPool.AddLast(pair.Value); } } } }