Ejemplo n.º 1
0
        /// <summary>
        /// 绑定连接
        /// </summary>
        public void BindSocket(PlayerInfoData playerInfo, Socket socket)
        {
            try
            {
                int index = unknownSocket.IndexOf(socket);
                //添加到已绑定的socket列表
                PlayerSocket playerSocket = new PlayerSocket(playerInfo, socket);
                freedomPlayer.Add(playerSocket);

                //从未知连接列表中删除
                unknownSocket.Remove(socket);

                //日志记录
                LogsSystem.Instance.Print(string.Format("绑定成功[{0},{1}]", playerInfo.playerName, socket.RemoteEndPoint.ToString()));

                //绑定后尝试分配房间
                TryAllocRoom();
            }
            catch (Exception ex)
            {
                LogsSystem.Instance.Print("绑定连接失败,可能是不存在该连接:" + ex.ToString(), LogLevel.WARN);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据UUID做
        /// 身份验证处理
        /// </summary>
        private GameData ProcessIdentify(string uuid, Socket socket)
        {
            try
            {
                PlayerInfoData playerInfo = new PlayerInfoData();
                playerInfo.playerUUID = uuid;

                string command = string.Format("SELECT * FROM account WHERE UUID = '{0}'", uuid);
                DataSet ds = MySQLHelper.GetDataSet(MySQLHelper.Conn, CommandType.Text, command, null);
                if (ds.Tables[0].Rows.Count > 0)//UUID验证通过
                {
                    //获取UID
                    int uid = Convert.ToInt32(ds.Tables[0].Rows[0]["Uid"]);
                    playerInfo.playerUid = uid;

                    //获取玩家名字
                    command = string.Format("SELECT * FROM playerinfo WHERE Uid = '{0}'", uid);
                    ds = MySQLHelper.GetDataSet(MySQLHelper.Conn, CommandType.Text, command, null);
                    playerInfo.playerName = ds.Tables[0].Rows[0]["PlayerName"].ToString();

                    //绑定
                    TcpServer.Instance.GetGameRoomManager().BindSocket(playerInfo, socket);

                    //添加入玩家管理
                    PlayerManager.Instance.PlayerLoginGameServer(playerInfo.playerUid, playerInfo.playerName, playerInfo.playerUUID, socket);
                }
                else
                {
                    LogsSystem.Instance.Print("未知的UUID试图绑定连接", LogLevel.WARN);
                }
            }
            catch (Exception ex)
            {
                LogsSystem.Instance.Print("发生异常" + ex.ToString(), LogLevel.ERROR);
            }
            return null;
        }
Ejemplo n.º 3
0
 public PlayerSocket(PlayerInfoData info, Socket socket)
 {
     this.playerInfo = info;
     this.socket = socket;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 玩家登陆游戏服务器
        /// </summary>
        public void PlayerLoginGameServer(int uid, string playerName, string UUID, Socket socket)
        {
            //检查玩家是否已经登陆。如果已登陆则踢出之前的
            foreach (PlayerSocket onlinePlayer in gamePlayerList)
            {
                string onlinePlayerUUID = onlinePlayer.playerInfo.playerUUID;
                if (onlinePlayerUUID == UUID)
                {
                    GameData data = new GameData();
                    data.operateCode = OperateCode.Offline;
                    data.returnCode = ReturnCode.Refuse;

                    TcpServer.Instance.Send(onlinePlayer.socket, data);

                    //TcpServer.Instance.
                    //UdpServer.Instance.SendMsg(JsonCoding<GameData>.encode(model), onlinePlayer.IPed.Address.ToString(), onlinePlayer.IPed.Port);//发送断线消息
                    this.gamePlayerList.Remove(onlinePlayer);
                }
            }

            //登陆系统
            PlayerInfoData pid = new PlayerInfoData();
            pid.playerUid = uid;
            pid.playerName = playerName;
            pid.playerUUID = UUID;

            PlayerSocket ps = new PlayerSocket(pid, socket);
            this.gamePlayerList.Add(ps);
        }