Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            SqlConn.ConnectDatabase();
            TypeDo.AddType();
            Server srv = new Server();

            srv.Start("192.168.1.5", 62345); //127.0.0.1
            SqlConn.InitializePersenInfo();
            while (true)
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                FrameUpdate();

                stopwatch.Stop();

                long sleepTime = FrameTimeMs - stopwatch.ElapsedMilliseconds;
                // System.Console.WriteLine(stopwatch.ElapsedMilliseconds);
                if (sleepTime > 0)//执行时间测试
                {
                    Thread.Sleep((int)sleepTime);
                }
            }
        }
        public override void DoCommand()
        {
            byte[]       content    = Decode.DecodeFirstContendBtyes(bytes);
            LoginInfo    myInfo     = DataDo.Json2Object <LoginInfo>(content);
            string       strContent = "SELECT * FROM counter where id=" + myInfo.id + " ;";
            PersonalInfo user       = SqlConn.Select(strContent);

            if (user != null)
            {
                if (user.password == myInfo.passWord)
                {
                    Console.WriteLine("用户登陆成功");
                    Server.AddUser(myInfo.id, conn);
                    conn.ID = myInfo.id;                    //客户端的id作为属性存起来了便于访问

                    user.status = (int)PersonStatus.OnLine; //在线
                    PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine);
                    conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(user)));
                }
                else
                {
                    Console.WriteLine("密码错误");
                    //回客户端消息
                }
            }
            else
            {
                Console.WriteLine("账号不存在");
                //回客户端消息
            }
        }
        public override void DoCommand()
        {
            int    id                   = BitConverter.ToInt32(bytes, 8);
            string strContent           = "SELECT * from  friends right JOIN counter ON friends.f_id=counter.id where friends.user_id = " + id + " ORDER BY status DESC;";
            List <PersonalInfo> friends = SqlConn.FindFriends(strContent);

            Console.WriteLine("用户:" + id + "的好友数:" + friends.Count);
            conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(friends)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 改变状态信息【退出房间都不会修改玩家房间号,下次进入房间会自动更替】
        /// </summary>
        public static void ChangeStatusInfo(int id, string roomId, int status)
        {
            string where = "id = '" + id + "'";
            string roomCondition = "";

            if (status == (int)PersonStatus.Combine || status == (int)PersonStatus.Fighting)
            {
                roomCondition = "roomNum = '" + roomId + "',";
            }
            SqlConn.AlterInfo("counter", roomCondition + "status='" + status + "'", where);
        }
Ejemplo n.º 5
0
        public override void DoCommand()
        {
            LoginInfo myInfo = DataDo.Json2Object <LoginInfo>(Decode.DecodeFirstContendBtyes(bytes));
            string    id     = SqlConn.Insert(myInfo.userName, myInfo.passWord); // 添加到数据库 通过访问数据库获取自动分配的id

            Server.AddUser(id, conn);                                            //添加到服务器连接字典里去
            conn.ID = id;                                                        //客户端的id作为属性存起来了便于访问
            //Console.WriteLine("获取id:" + id);
            string       strContent = "SELECT * FROM counter where id=" + id + " ;";
            PersonalInfo user       = SqlConn.Select(strContent);

            if (user != null)
            {
                //Console.WriteLine("用户登陆成功");
                user.status = (int)PersonStatus.OnLine;//在线(发送数据修改)
                PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine);
                conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(user)));
            }
        }
Ejemplo n.º 6
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); //清除离线客户
        }
Ejemplo n.º 7
0
        public override void DoCommand()                  //世界排行榜    还有一个没做
        {
            List <PersonalInfo> rank = SqlConn.GetRank(); //直接向数据库查询 获取排行榜

            conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(rank)));
        }