SetKey() private method

private SetKey ( uint key ) : bool
key uint
return bool
Beispiel #1
0
        //--------------------------------------
        private void HandleEnterScene(Msg_LR_EnterScene msg, PBChannel channel, int handle, uint seq)
        {
            ulong guid   = msg.UserGuid;
            int   roomId = msg.RoomID;
            bool  isFieldThread;
            int   ix = GetActiveRoomThreadIndex(roomId, out isFieldThread);

            if (ix < 0)
            {
                Msg_RL_EnterSceneResult replyBuilder = new Msg_RL_EnterSceneResult();
                replyBuilder.UserGuid = guid;
                replyBuilder.RoomID   = roomId;
                replyBuilder.Result   = (int)SceneOperationResultEnum.Cant_Find_Room;
                channel.Send(replyBuilder);
            }
            else
            {
                RoomThread roomThread;
                if (isFieldThread)
                {
                    roomThread = field_roomthread_list_[ix];
                }
                else
                {
                    roomThread = roomthread_list_[ix];
                }
                Msg_LR_RoomUserInfo rui = msg.UserInfo;

                User rsUser = user_pool_.NewUser();
                LogSys.Log(LOG_TYPE.INFO, "NewUser {0} for {1} {2}", rsUser.LocalID, rui.Guid, rui.Key);
                rsUser.Init();
                if (!rsUser.SetKey(rui.Key))
                {
                    LogSys.Log(LOG_TYPE.WARN, "user who's key is {0} already in room!", rui.Key);
                    LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for {1} {2}, [RoomManager.HandleEnterScene]", rsUser.LocalID, rui.Guid, rui.Key);
                    user_pool_.FreeUser(rsUser.LocalID);

                    Msg_RL_EnterSceneResult replyBuilder = new Msg_RL_EnterSceneResult();
                    replyBuilder.UserGuid = guid;
                    replyBuilder.RoomID   = roomId;
                    replyBuilder.Result   = (int)SceneOperationResultEnum.User_Key_Exist;
                    channel.Send(replyBuilder);
                }
                else
                {
                    rsUser.LobbyUserData = rui;
                    if (rui.IsMachine == true)
                    {
                        rsUser.UserControlState = (int)UserControlState.Ai;
                    }
                    else
                    {
                        rsUser.UserControlState = (int)UserControlState.User;
                    }
                    if (msg.HP > 0 && msg.MP > 0)
                    {
                        rsUser.SetHpArmor(msg.HP, msg.MP);
                    }

                    if (rui.EnterX > 0 && rui.EnterY > 0)
                    {
                        rsUser.SetEnterPoint(rui.EnterX, rui.EnterY);
                    }

                    roomThread.QueueAction(roomThread.AddUser, rsUser, roomId, (MyAction <bool, int, User>)((bool success, int sceneId, User user) => {
                        if (success)
                        {
                            Msg_RL_EnterSceneResult replyBuilder = new Msg_RL_EnterSceneResult();
                            replyBuilder.UserGuid = guid;
                            replyBuilder.RoomID   = roomId;
                            replyBuilder.Result   = (int)SceneOperationResultEnum.Success;
                            channel.Send(replyBuilder);
                        }
                        else
                        {
                            Msg_RL_EnterSceneResult replyBuilder = new Msg_RL_EnterSceneResult();
                            replyBuilder.UserGuid = guid;
                            replyBuilder.RoomID   = roomId;
                            replyBuilder.Result   = (int)SceneOperationResultEnum.Cant_Find_Room;
                            channel.Send(replyBuilder);
                        }
                    }));
                }
            }
        }