예제 #1
0
        /// <summary>
        /// 退出房间
        /// </summary>
        void ExitRoom()
        {
            RoomMsg  roomMsg  = DataDo.Json2Object <RoomMsg>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(roomMsg.roomNum);

            if (roomInfo != null)
            {
                PersonalInfo.ChangeStatusInfo(roomMsg.otherId, "", (int)PersonStatus.OnLine);

                PersonalInfo people = roomInfo.member.Find(it =>
                {
                    if (it.id == roomMsg.otherId)//找到要删的人
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                roomInfo.RemoveMember(people.id);
                //if (roomMsg.otherId == roomInfo.host_Id && roomInfo.member.Count>0)//退出者的ID为房主
                //{
                //    roomInfo.host_Id = roomInfo.member[0].id;//房主转移
                //}
                Console.WriteLine("剩余人数:" + roomInfo.member.Count);
            }
        }
예제 #2
0
        void ReturnRoom()
        {
            Info     info     = DataDo.Json2Object <Info>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(info.roomId);

            if (roomInfo != null)
            {
                PersonalInfo personal = roomInfo.member.Find(it => {
                    if (it.id == info.myId)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (personal != null)
                {
                    personal.IsInWaitRoom = true;
                }
                //在房间的都知道

                conn.SendBts(Incode.IncodeSecondaryCommand(type, (int)SecondCommands.TurnBackROOM, DataDo.Object2Json(roomInfo)));
                Conn _conn;
                for (int i = 0; i < roomInfo.member.Count; i++)
                {
                    if (roomInfo.member[i].id != info.myId)
                    {
                        Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out _conn);
                        _conn.SendBts(Incode.IncodeSecondaryCommand(type, (int)SecondCommands.JOINROOM, DataDo.Object2Json(roomInfo)));
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 加入房间(及时响应)
        /// </summary>
        void JoinRoom()
        {
            RoomMsg  roomMsg  = DataDo.Json2Object <RoomMsg>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(roomMsg.roomNum);

            if (roomInfo != null)
            {
                PersonalInfo.ChangeStatusInfo(roomMsg.my.id, roomInfo.roomID, (int)PersonStatus.Combine);
                roomMsg.my.IsInWaitRoom = true;
                roomInfo.AddMember(roomMsg.my);
                if (roomInfo.member.Count == RoomInfo.MaxSIZE)//房间人满
                {
                    freeRooms.Remove(roomInfo.roomID);
                }
                ForeachSendRoom((int)SecondCommands.JOINROOM, roomInfo);
                Console.WriteLine("加入成功");
            }
        }
예제 #4
0
        /// <summary>
        /// 擦出所有数据
        /// </summary>
        /// <param name="conn"></param>
        void RemoveData(Conn conn)
        {
            //修改个人状态
            PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OffLine);
            //房间移除成员
            string       strContent = "SELECT * FROM counter where id=" + conn.ID + " ;";
            PersonalInfo user       = SqlConn.Select(strContent);

            ConsoleHelper.WriteColorLine("用户:" + user.id + "已超时断开连接   所在房间:" + user.roomNum, ConsoleColor.Red);

            //玩家退出不修改其所在房间的id值,为以后做离线重连继续战斗做准备
            RoomInfo roomInfo = GameCommand.GetRoom(user.roomNum);

            if (roomInfo != null)
            {
                roomInfo.RemoveMember(user.id);
            }

            Server.connMap.Remove(conn.ID);           //清除连接
            Server.connHeartTime.Remove(conn.ID);     //清除心跳包
            OffLineDetection.clients.Remove(conn.ID); //清除离线客户
        }