예제 #1
0
파일: Room.cs 프로젝트: weacw/FIGHT
        public void Exitintheroom(Clientpeer _clientpeer)
        {
            if (!roomdata.clientpeers.Contains(_clientpeer))
            {
                return;
            }
            roomdata.clientpeers.Remove(_clientpeer);
            _clientpeer.isjoinedroom = false;
            _clientpeer.joinedroom   = null;

            if (roomdata.roommaster.Equals(_clientpeer) && roomdata.clientpeers.Count <= 1)
            {
                Dismiss();
            }
            else if (roomdata.roommaster.Equals(_clientpeer) && roomdata.clientpeers.Count > 1)
            {
                roomdata.roommaster = roomdata.clientpeers[0];
            }
            else
            {
                string playername = _clientpeer.playerdata.playername;
                if (FIGHTserverapplication.Getfightserverapplication().clientpeers.ContainsKey(playername))
                {
                    FIGHTserverapplication.Getfightserverapplication().clientpeers.Remove(playername);
                    FIGHTserverapplication.Getfightserverapplication().clientpeers.Add(playername, _clientpeer);
                    log.Info(playername + " has left the " + roomdata.Roomname + " to the lobby. ");
                }
            }
            log.Info("exit in the room:  " + _clientpeer.playerdata.playerid + "-" + _clientpeer.playerdata.playername);
        }
예제 #2
0
        /// <summary>
        /// 加入房间
        /// </summary>
        /// <param name="_request">如上</param>
        /// <param name="response">如上</param>
        /// <param name="_clientpeer">如上</param>
        private void Joinroom(OperationRequest _request, OperationResponse response, Clientpeer _clientpeer)
        {
            //解析客户端发送的请求
            object roomidobj, roompsdobj;

            _request.Parameters.TryGetValue((byte)Parametercode.ROOMID, out roomidobj);
            _request.Parameters.TryGetValue((byte)Parametercode.ROOMPSD, out roompsdobj);

            if (roomidobj == null)
            {
                return;
            }
            int    roomid  = int.Parse(roomidobj.ToString());
            string roompsd = roompsdobj.ToString();

            if (!FIGHTserverapplication.Getfightserverapplication().rooms.ContainsKey(roomid))
            {
                return;
            }
            Room roomitem = FIGHTserverapplication.Getfightserverapplication().rooms[roomid];

            roomitem.Joinroom(_clientpeer, roompsd);


            //服务器端回馈客户端的操作码-加入房间的操作码
            response.ReturnCode = (byte)Returncode.JOINEDROOM;

            //服务器端回馈客户端的数据
            response.Parameters = new Dictionary <byte, object>();
            ParameterTool.AddParameter(response.Parameters, Parametercode.ROOMDATA, roomitem.roomdata);
        }
예제 #3
0
파일: Room.cs 프로젝트: weacw/FIGHT
        public void Dismiss()
        {
            roomdata.roommaster = null;
            roomdata.clientpeers.Clear();
            roomdata.clientpeers = null;
            FIGHTserverapplication.Getfightserverapplication().rooms.Remove(roomdata.Roomid);


            log.Info("room: " + roomdata.Roomid + " - " + roomdata.Roomname + " iss dismissed");

            roomdata = null;
        }
예제 #4
0
        /// <summary>
        /// 获取房间列表
        /// </summary>
        /// <param name="_response">服务器回馈客户端的请求</param>
        private void Getroom(OperationResponse _response)
        {
            //服务器端回馈客户端的操作码-获取房间列表的操作码
            _response.ReturnCode = (byte)Returncode.GETROOMLIST;

            //服务器端回馈客户端的数据
            _response.Parameters = new Dictionary <byte, object>();
            List <Roomdata> roomlist = new List <Roomdata>();

            foreach (KeyValuePair <int, Room> room in FIGHTserverapplication.Getfightserverapplication().rooms)
            {
                roomlist.Add(room.Value.roomdata);
            }
            ParameterTool.AddParameter(_response.Parameters, Parametercode.ROOMCOUNT, FIGHTserverapplication.Getfightserverapplication().rooms.Count);
            ParameterTool.AddParameter(_response.Parameters, Parametercode.ROOMDATA, roomlist);
        }
예제 #5
0
파일: Clientpeer.cs 프로젝트: weacw/FIGHT
        protected override void OnOperationRequest(OperationRequest _operationrequest, SendParameters _sendparameters)
        {
            Handlerbase handler;

            FIGHTserverapplication.Getfightserverapplication()
            .handlers.TryGetValue(_operationrequest.OperationCode, out handler);
            OperationResponse response = new OperationResponse();

            response.OperationCode = _operationrequest.OperationCode;
            response.Parameters    = new Dictionary <byte, object>();
            if (handler != null)
            {
                handler.OnHandlerMessage(_operationrequest, response, this, _sendparameters);
                SendOperationResponse(response, _sendparameters);
            }
            else
            {
                log.Info("can not find handler from operation code : " + _operationrequest.OperationCode);
            }
        }
예제 #6
0
파일: Clientpeer.cs 프로젝트: weacw/FIGHT
        protected override void OnDisconnect(DisconnectReason _reasoncode, string _reasondetail)
        {
            if (!isjoinedroom)
            {
                if (playerdata == null)
                {
                    log.Info(_reasoncode + ":" + _reasoncode + "|" + defaultdata.defaultid + "-" + defaultdata.defaultname + "has been disconnected.");
                    //释放默认信息
                    defaultdata.defaultid   = null;
                    defaultdata.defaultname = null;
                    defaultdata             = null;
                    return;
                }

                log.Info(_reasoncode + ":" + _reasoncode + "|" + playerdata.playerid + "-" + playerdata.playername + "has been disconnected.");
                if (FIGHTserverapplication.Getfightserverapplication().clientpeers.ContainsKey(playerdata.playername))
                {
                    FIGHTserverapplication.Getfightserverapplication().clientpeers.Remove(playerdata.playername);
                }


                //释放玩家信息
                playerdata.playername = null;
                playerdata.playerid   = 0;
                playerdata            = null;

                //释放默认信息
                defaultdata.defaultid   = null;
                defaultdata.defaultname = null;
                defaultdata             = null;
                return;
            }


            joinedroom.Exitintheroom(this);
            if (FIGHTserverapplication.Getfightserverapplication().clientpeers.ContainsKey(playerdata.playername))
            {
                FIGHTserverapplication.Getfightserverapplication().clientpeers.Remove(playerdata.playername);
            }
            playerdata = null;
        }
예제 #7
0
파일: Room.cs 프로젝트: weacw/FIGHT
        public void Joinroom(Clientpeer _clientpeer, string _roompassword)
        {
            if (String.Compare(_roompassword, roomdata.Roompassword, StringComparison.Ordinal) != 0)
            {
                //TODO:发送密码错误消息回馈至客户端
                return;
            }

            string clientname = _clientpeer.playerdata.playername;

            if (roomdata.clientpeers.Count < 0)
            {
                if (!roomdata.clientpeers.Contains(_clientpeer) || !_clientpeer.Equals(roomdata.roommaster))
                {
                    roomdata.clientpeers.Add(_clientpeer);
                    log.Info("client: " + clientname + " join " + roomdata.Roomname + " room");
                }
                else
                {
                    log.Info("client: " + clientname + " is already in the " + roomdata.Roomname + " room");
                }
            }
            else
            {
                if (roomdata.clientpeers.Contains(_clientpeer))
                {
                    return;
                }
                roomdata.clientpeers.Add(_clientpeer);
                log.Info("Master " + clientname + " join " + roomdata.Roomname);
            }

            if (!FIGHTserverapplication.Getfightserverapplication().clientpeers.ContainsKey(clientname))
            {
                return;
            }
            FIGHTserverapplication.Getfightserverapplication().clientpeers.Remove(clientname);
            FIGHTserverapplication.Getfightserverapplication().clientpeers.Add(clientname, null);
            _clientpeer.isjoinedroom = true;
            _clientpeer.joinedroom   = this;
        }
예제 #8
0
        /// <summary>
        /// 离开房间操作
        /// </summary>
        /// <param name="_request">客户端发起的请求</param>
        /// <param name="_response">服务器回馈客户端的请求</param>
        /// <param name="_clientpeer">客户端</param>
        private void Leaveroom(OperationRequest _request, OperationResponse _response, Clientpeer _clientpeer)
        {
            //解析客户端发送的请求操作
            object roomobj;

            _request.Parameters.TryGetValue((byte)Parametercode.ROOMID, out roomobj);
            if (roomobj == null)
            {
                return;
            }
            Room roomitem = FIGHTserverapplication.Getfightserverapplication().rooms[int.Parse(roomobj.ToString())];

            roomitem.Exitintheroom(_clientpeer);

            //服务器端回馈客户端操作码-离开房间的操作码
            _response.ReturnCode = (byte)Returncode.LEFTROOM;

            //服务器端回馈客户端的数据
            _response.Parameters = new Dictionary <byte, object>();
            ParameterTool.AddParameter(_response.Parameters, Parametercode.PLAYERDATA, roomitem, true);
        }
예제 #9
0
        public override void OnHandlerMessage(OperationRequest _request, OperationResponse _response, Clientpeer _peer,
                                              SendParameters _sendparameters)
        {
            //提取当前发起登入客户端所发送的数据
            object playerobj = null;

            _request.Parameters.TryGetValue((byte)Parametercode.CHARACTERNAME, out playerobj);
            if (playerobj == null)
            {
                return;
            }
            string playername = (string)playerobj;

            //检查服务器中是否已经存在当前发起登入的客户端用户名称
            if (FIGHTserverapplication.Getfightserverapplication().clientpeers.ContainsKey(playername))
            {
                log.Info("Character name is already exists");
                _response.ReturnCode = (byte)Returncode.CHARACTERNAMEISEXIST;
                return;
            }

            //添加当前登入的客户端到服务器用户标内
            FIGHTserverapplication.Getfightserverapplication().clientpeers.Add(playername, _peer);
            log.Info("Character name: " + playername + " is Successful signin");

            //创建用户数据
            Playerdata playerdata = new Playerdata();

            playerdata.playername = playername;
            playerdata.playerid   = playerdata.GetHashCode();

            //链接用户数据到当前登入的客户端
            _peer.playerdata = playerdata;

            //反馈客户端登入操作完成并且成功
            _response.ReturnCode = (byte)Returncode.CHARACTERCREATED;
        }
예제 #10
0
파일: Handlerbase.cs 프로젝트: weacw/FIGHT
 public Handlerbase()
 {
     FIGHTserverapplication.Getfightserverapplication().handlers.Add((byte)Opcode, this);
     log.Info("Handler: " + GetType().Name + " is registered");
 }