Esempio n. 1
0
 public void Setup(ClientUID client_uid, InterServerID srv_uid, PlayerInfoForWS info)
 {
     m_char_idx   = info.char_idx;
     m_client_uid = client_uid;
     m_srv_uid    = srv_uid;
     m_player_data.Copy(info);
 }
Esempio n. 2
0
        /// <summary>
        /// 进入游戏
        /// </summary>
        private void OnEnterGame(PacketBase packet)
        {
            gs2ss.EnterGame msg        = packet as gs2ss.EnterGame;
            ClientUID       client_uid = msg.client_uid;
            InterServerID   server_uid = msg.server_uid;

            UnitManager.Instance.AddSession(client_uid);

            if (!UnitManager.Instance.HasUnit(msg.char_idx))
            {
                DBID db_id = new DBID();
                db_id.game_id = ServerConfig.GetDBByAccountIdx(msg.account_idx, eDBType.Game);
                PlayerInfoForSS ss_data = CommonObjectPools.Spawn <PlayerInfoForSS>();
                SQLCharHandle.QueryCharacterInfo(msg.char_idx, db_id, ss_data, is_load =>
                {
                    if (is_load && UnitManager.Instance.HadSession(client_uid))
                    {//读取玩数据,有可能已经退出
                        //创建玩家
                        Player player     = new Player();
                        player.client_uid = client_uid;
                        player.LoadData(ss_data);
                        UnitManager.Instance.AddUnit(player);

                        //告诉gs成功进入游戏
                        ss2gs.EnterGame rep_gs_msg = PacketPools.Get(ss2gs.msg.ENTER_GAME) as ss2gs.EnterGame;
                        rep_gs_msg.server_uid      = server_uid;
                        rep_gs_msg.client_uid      = client_uid;
                        rep_gs_msg.char_idx        = ss_data.char_idx;
                        ServerNetManager.Instance.Send(server_uid.gs_uid, rep_gs_msg);

                        //告诉ws
                        ss2ws.LoginClient rep_ws_msg = PacketPools.Get(ss2ws.msg.LOGIN_CLIENT) as ss2ws.LoginClient;
                        rep_ws_msg.server_uid        = server_uid;
                        rep_ws_msg.client_uid        = client_uid;
                        rep_ws_msg.data.Copy(ss_data);
                        ServerNetManager.Instance.Send2WS(rep_ws_msg);

                        //告诉gl
                        ss2gl.LoginClient rep_gl_msg = PacketPools.Get(ss2gl.msg.LOGIN_CLIENT) as ss2gl.LoginClient;
                        rep_gl_msg.server_uid        = server_uid;
                        rep_gl_msg.data.Copy(ss_data);
                        ServerNetManager.Instance.Send2GL(rep_gl_msg);

                        //告诉客户端角色基础信息
                        ss2c.CharacterInfo rep_msg = PacketPools.Get(ss2c.msg.CHARACTER_INFO) as ss2c.CharacterInfo;
                        rep_msg.data.Copy(ss_data);
                        ServerNetManager.Instance.SendProxy(client_uid, rep_msg, false);

                        //初始化内部逻辑
                        player.OnFirstEnter();
                    }
                    CommonObjectPools.Despawn(ss_data);
                });
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 登入处理
        /// </summary>
        public void HandleLogin(ClientUID client_uid, InterServerID srv_uid, PlayerInfoForWS data)
        {
            Unit unit = GetUnitByIdx(data.char_idx);

            if (unit != null)
            {//可能上次退出时,没有清除数据
                this.RemoveUnit(unit);
            }
            //创建玩家
            unit = new Unit();
            unit.Setup(client_uid, srv_uid, data);
            UnitManager.Instance.AddUnit(unit);
            unit.OnEnter();
        }
Esempio n. 4
0
        private void OnCharacterInfo(PacketBase packet)
        {
            ss2db.CharacterInfo msg = packet as ss2db.CharacterInfo;

            PlayerCache member = PlayerCacheManager.Instance.GetMember(msg.char_idx);

            if (member == null)
            {
                //由于数据包会放入对象池,所以在这先保存临时数据
                ClientUID client_uid = msg.client_uid; InterServerID server_uid = msg.server_uid; long char_idx = msg.char_idx;
                PlayerCacheManager.Instance.LoadPlayer(msg.char_idx, idx =>
                {
                    OnCharacterInfoLoaded(client_uid, server_uid, char_idx);
                });
            }
            else
            {
                OnCharacterInfoLoaded(msg.client_uid, msg.server_uid, msg.char_idx);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 创建角色
        /// </summary>
        private void OnCreateCharacter(PacketBase packet)
        {
            ss2db.CreateCharacter msg = packet as ss2db.CreateCharacter;

            InterServerID       server_uid  = msg.server_uid;
            ClientUID           client_uid  = msg.client_uid;
            CreateCharacterInfo create_info = msg.data;

            create_info.char_idx = ServerNetManager.Instance.GetNextCharIdx();

            SQLCharHandle.CreateCharacter(msg.account_idx, create_info, (res) =>
            {
                eCreateCharResult result = eCreateCharResult.E_FAILED_COMMONERROR;
                if (create_info.char_idx == res)
                {
                    result = eCreateCharResult.E_SUCCESS;
                }
                else
                {
                    switch (res)
                    {
                    case 0: result = eCreateCharResult.E_FAILED_INTERNALERROR; break;

                    case 1: result = eCreateCharResult.E_FAILED_CHARCOUNTLIMIT; break;

                    case 2: result = eCreateCharResult.E_FAILED_INVALIDPARAM_REPEATEDNAME; break;

                    case 3: result = eCreateCharResult.E_FAILED_COMMONERROR; break;
                    }
                }

                db2ss.CreateCharacter rep_msg = PacketPools.Get(db2ss.msg.CREATE_CHARACTER) as db2ss.CreateCharacter;
                rep_msg.server_uid            = server_uid;
                rep_msg.client_uid            = client_uid;
                rep_msg.char_idx  = create_info.char_idx;
                rep_msg.char_name = create_info.char_name;
                rep_msg.result    = result;
                this.Send(rep_msg);
            }
                                          );
        }
Esempio n. 6
0
        /// <summary>
        /// 角色列表
        /// </summary>
        private void OnEnumCharacter(PacketBase packet)
        {
            ss2db.EnumCharacter msg = packet as ss2db.EnumCharacter;

            InterServerID server_uid = msg.server_uid;
            ClientUID     client_uid = msg.client_uid;

            SQLCharHandle.QueryCharacterList(msg.account_idx, (data) =>
            {
                db2ss.EnumCharacter rep_msg = PacketPools.Get(db2ss.msg.ENUM_CHAR) as db2ss.EnumCharacter;
                rep_msg.server_uid          = server_uid;
                rep_msg.client_uid          = client_uid;
                foreach (var char_data in data)
                {
                    rep_msg.list.Add(char_data);
                }
                rep_msg.result = eEnumCharResult.E_SUCCESS;
                this.Send(rep_msg);
            }
                                             );
        }
Esempio n. 7
0
        private void OnCharacterInfoLoaded(ClientUID client_uid, InterServerID server_uid, long char_idx)
        {
            PlayerCache member = PlayerCacheManager.Instance.GetMember(char_idx);

            if (member == null)
            {
                Log.Warning("OnPlayerInfoLoaded - 未找到玩家缓存信息:" + char_idx);
                return;
            }
            //设置服务器信息
            member.client_uid = client_uid;
            member.ss_uid     = server_uid.ss_uid;
            member.UpdateAttribute(eUnitModType.UMT_time_last_login, Time.second_time);

            //返回数据给ss
            db2ss.CharacterInfo rep_msg = PacketPools.Get(db2ss.msg.CHARACTER_INFO) as db2ss.CharacterInfo;
            rep_msg.server_uid = server_uid;
            rep_msg.client_uid = client_uid;
            rep_msg.data.Copy(member.ss_data);
            this.Send(rep_msg);

            //读取邮件
            MailCacheManager.Instance.LoadMailbox(member.char_idx);
        }
Esempio n. 8
0
 public void Set(InterServerID server_uid, PackBaseS2S packet)
 {
     packet.server_uid = server_uid;
     packet.Write(data);
 }