AddSameRoomUser() private method

private AddSameRoomUser ( User user ) : void
user User
return void
Example #1
0
 public bool AddNewUser(User newUser)
 {
     foreach (User us in m_RoomUsers)
     {
         if (us != null && us.Guid == newUser.Guid)
         {
             //当前玩家已在游戏房间内
             if (us.GetKey() == newUser.GetKey())
             {
                 LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomId:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                            m_RoomId, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                 LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for new {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey());
                 m_UserPool.FreeUser(newUser.LocalID);
                 return(true);
             }
             else if (us.UserControlState != (int)UserControlState.User)
             {
                 LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomId:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                            m_RoomId, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                 LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for old {1} {2}, [Room.AddNewUser]", us.LocalID, us.Guid, us.GetKey());
                 RemoveUser(us);
                 break;
             }
             else
             {
                 LogSys.Log(LOG_TYPE.DEBUG, "Add user false: User already in the room and online! RoomId:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                            m_RoomId, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                 LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for new {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey());
                 m_UserPool.FreeUser(newUser.LocalID);
                 return(false);
             }
         }
     }
     newUser.EnterRoomTime      = TimeUtility.GetLocalMilliseconds();
     newUser.OwnRoomUserManager = this;
     newUser.RegisterObservers(m_RoomObservers);
     newUser.CharacterCreateTime = TimeUtility.GetLocalMilliseconds();
     newUser.TimeCounter         = 0;
     if ((int)UserControlState.Ai == newUser.UserControlState)
     {
         newUser.IsEntered = true;
     }
     if (null != m_ActiveScene && m_ActiveScene.SceneState == SceneState.Running)
     {
         Scene scene = m_ActiveScene;
         scene.EnterScene(newUser);
     }
     foreach (User otheruser in m_RoomUsers)
     {
         if (otheruser != null)
         {
             otheruser.AddSameRoomUser(newUser);
             newUser.AddSameRoomUser(otheruser);
         }
     }
     m_RoomUsers.Add(newUser);
     LogSys.Log(LOG_TYPE.DEBUG, "Add user success ! RoomId:{0} , UserGuid:{1}({2})",
                m_RoomId, newUser.Guid, newUser.GetKey());
     return(true);
 }
Example #2
0
        internal bool AddNewUser(User newUser)
        {
            foreach (User us in room_users_) {
                if (us != null && us.Guid == newUser.Guid) {
                    //当前玩家已在游戏房间内
                    if (us.GetKey() == newUser.GetKey()) {
                        LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomID:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                        cur_room_id_, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                        LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for new {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey());
                        user_pool_.FreeUser(newUser.LocalID);
                        return true;
                    } else if (us.UserControlState != (int)UserControlState.User) {
                        LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomID:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                        cur_room_id_, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                        LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for old {1} {2}, [Room.AddNewUser]", us.LocalID, us.Guid, us.GetKey());
                        RemoveUser(us);
                        break;
                    } else {
                        LogSys.Log(LOG_TYPE.DEBUG, "Add user false: User already in the room and online! RoomID:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                        cur_room_id_, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                        LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for new {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey());
                        user_pool_.FreeUser(newUser.LocalID);
                        return false;
                    }
                }
            }
            can_close_time_ = 0;
            newUser.EnterRoomTime = TimeUtility.GetLocalMilliseconds();
            newUser.OwnRoom = this;
            newUser.RegisterObservers(room_observers_);
            newUser.CharacterCreateTime = TimeUtility.GetLocalMilliseconds();
            newUser.TimeCounter = 0;
            if ((int)UserControlState.Ai == newUser.UserControlState) {
                newUser.IsEntered = true;
            }
            if (null != m_ActiveScene && m_ActiveScene.SceneState == SceneState.Running) {
                Scene scene = m_ActiveScene;
                scene.EnterScene(newUser);
            }
            foreach (User otheruser in room_users_) {
                if (otheruser != null) {
                    otheruser.AddSameRoomUser(newUser);
                    newUser.AddSameRoomUser(otheruser);
                }
            }
            room_users_.Add(newUser);
            LogSys.Log(LOG_TYPE.DEBUG, "Add user success ! RoomID:{0} , UserGuid:{1}({2})",
              cur_room_id_, newUser.Guid, newUser.GetKey());

            m_CanFinish = true;
            return true;
        }