Esempio n. 1
0
        void OnReqTestDB(int workerIndex, GameServerSession session, string cmd, JObject jObjRecv)
        {
            Random rand    = new Random();
            string show_id = jObjRecv["show_id"].ToString();
            string token   = jObjRecv["token"].ToString();

            //参数验证
            if (show_id.Trim().Length == 0)
            {
                return;
            }
            if (token.Trim().Length == 0)
            {
                return;
            }

            var dbLink = Program.dbSvc.GetLink(workerIndex);

            if (!CheckToken(dbLink, show_id, token))
            {
                Program.server.SendError(session, cmd, "token非法或已过期");
                return;
            }

            long money = (long)RandomUtil.RandomMinMax(rand, 1000000, 2000000);

            Program.dbHelper.SetUserMoney(dbLink, money, show_id);

            Program.server.SendSuccess(session, cmd);
        }
Esempio n. 2
0
 public NetMessage(int action, GameServerSession session, string content = "", string closedCause = "", bool isClosedInternalCause = false)
 {
     this.action                = action;
     this.session               = session;
     this.content               = content;
     this.closedCause           = closedCause;
     this.isClosedInternalCause = isClosedInternalCause;
 }
Esempio n. 3
0
        Player GetPlayerFromSession(GameServerSession session)
        {
            foreach (var player in players.Values)
            {
                if (player.session == session)
                {
                    return(player);
                }
            }

            return(null);
        }
Esempio n. 4
0
 public void OnClosed(int workerIndex, GameServerSession session, string closedCause, bool isInternalCause)
 {
     //桌子分多线处理
     if (session.TableId > 0)
     {
         var table = GetTableFromId(session.TableId);
         if (table != null)
         {
             table.Leave(session, true);
         }
     }
 }
Esempio n. 5
0
        void OnReqOperateIngame(int workerIndex, GameServerSession session, string cmd, JObject jObjRecv)
        {
            string show_id = jObjRecv["show_id"].ToString();
            string token   = jObjRecv["token"].ToString();
            string subcmd  = jObjRecv["subcmd"].ToString();

            //参数验证
            if (show_id.Trim().Length == 0)
            {
                return;
            }
            if (token.Trim().Length == 0)
            {
                return;
            }

            var dbLink = Program.dbSvc.GetLink(workerIndex);

            if (!CheckToken(dbLink, show_id, token))
            {
                Program.server.SendError(session, cmd, "token非法或已过期");
                return;
            }

            if (subcmd.Length == 0)
            {
                return;
            }

            if (session.TableId == 0)
            {
                return;
            }

            var table = GetTableFromId(session.TableId);

            if (table == null)
            {
                return;
            }

            JObject jObjSend = new JObject();

            jObjSend["cmd"]    = cmd;
            jObjSend["subcmd"] = subcmd;

            table.OperateIngame(show_id, subcmd, jObjRecv, jObjSend);

            Program.server.Send(session, jObjSend);
        }
Esempio n. 6
0
        void OnReqGodInstruct(int workerIndex, GameServerSession session, string cmd, JObject jObjRecv)
        {
            string show_id = jObjRecv["show_id"].ToString();
            string token   = jObjRecv["token"].ToString();
            string subcmd  = jObjRecv["subcmd"].ToString();

            //参数验证
            if (show_id.Trim().Length == 0)
            {
                return;
            }
            if (token.Trim().Length == 0)
            {
                return;
            }

            var dbLink = Program.dbSvc.GetLink(workerIndex);

            if (!CheckToken(dbLink, show_id, token))
            {
                Program.server.SendError(session, cmd, "token非法或已过期");
                return;
            }

            if (subcmd.Length == 0)
            {
                return;
            }

            if (!Program.dbHelper.UserIsRobot(dbLink, show_id))
            {
                return;
            }

            if (subcmd == "set_money")
            {
                long money = (long)jObjRecv["money"];

                Program.dbHelper.SetUserMoney(dbLink, money, show_id);
            }

            JObject jObjSend = new JObject();

            jObjSend["cmd"]      = cmd;
            jObjSend["subcmd"]   = subcmd;
            jObjSend["ret_code"] = 0;

            Program.server.Send(session, jObjSend);
        }
Esempio n. 7
0
        public void OnReceived(int workerIndex, GameServerSession session, string content)
        {
            JObject jObjRecv = JObject.Parse(content);

            string cmd = jObjRecv["cmd"].ToString();

            Action <int, GameServerSession, string, JObject> handler;

            if (requestHandlers.TryGetValue(cmd, out handler))
            {
                Interlocked.Increment(ref totalRequest);

                handler(workerIndex, session, cmd, jObjRecv);
            }
        }
Esempio n. 8
0
        void OnReqJoinTable(int workerIndex, GameServerSession session, string cmd, JObject jObjRecv)
        {
            string show_id  = jObjRecv["show_id"].ToString();
            string token    = jObjRecv["token"].ToString();
            int    table_id = int.Parse(jObjRecv["table_id"].ToString());

            //参数验证
            if (show_id.Trim().Length == 0)
            {
                return;
            }
            if (token.Trim().Length == 0)
            {
                return;
            }

            var dbLink = Program.dbSvc.GetLink(workerIndex);

            if (!CheckToken(dbLink, show_id, token))
            {
                Program.server.SendError(session, cmd, "token非法或已过期");
                return;
            }

            if (session.TableId == 0 || session.TableId != table_id)
            {
                Program.server.SendError(session, cmd, "未找到该桌子");
                return;
            }

            Table table = GetTableFromId(table_id);

            if (table == null)
            {
                Program.server.SendError(session, cmd, "未找到该房间");
                return;
            }

            if (!table.Join(session, show_id))
            {
                Program.server.SendError(session, cmd, "房间已满");
                return;
            }

            Program.server.SendSuccess(session, cmd);
        }
Esempio n. 9
0
        public bool Leave(GameServerSession session, bool isCauseDisconnect)
        {
            Player player = GetPlayerFromSession(session);

            //不存在该玩家
            if (player == null)
            {
                return(false);
            }

            RemovePlayer(player, isCauseDisconnect);

            session.TableId = 0;

            NotifyJoinLeave("2", player.show_id);

            return(true);
        }
Esempio n. 10
0
        //桌子分多线处理
        void OnReqLeaveTable(int workerIndex, GameServerSession session, string cmd, JObject jObjRecv)
        {
            string show_id = jObjRecv["show_id"].ToString();
            string token   = jObjRecv["token"].ToString();

            //参数验证
            if (show_id.Trim().Length == 0)
            {
                return;
            }
            if (token.Trim().Length == 0)
            {
                return;
            }

            var dbLink = Program.dbSvc.GetLink(workerIndex);

            if (!CheckToken(dbLink, show_id, token))
            {
                Program.server.SendError(session, cmd, "token非法或已过期");
                return;
            }

            if (session.TableId == 0)
            {
                return;
            }

            var table = GetTableFromId(session.TableId);

            if (table == null)
            {
                return;
            }

            if (!table.Leave(session, false))
            {
                Program.server.SendError(session, cmd, "不存在该玩家");
                return;
            }

            Program.server.SendSuccess(session, cmd);
        }
Esempio n. 11
0
        public bool Join(GameServerSession session, string show_id)
        {
            //人数已满
            if (RemainSeatCount == 0)
            {
                return(false);
            }

            Player player = GetPlayer(show_id);

            if (player == null)
            {
                player          = new Player();
                player.is_robot = Program.dbHelper.UserIsRobot(dbLink, show_id);
                AddPlayer(show_id, player);
            }

            player.session = session;

            NotifyJoinLeave("1", player.show_id);

            return(true);
        }
Esempio n. 12
0
        void OnReqGetGameTable(int workerIndex, GameServerSession session, string cmd, JObject jObjRecv)
        {
            string show_id   = jObjRecv["show_id"].ToString();
            string token     = jObjRecv["token"].ToString();
            string game_name = jObjRecv["game_name"].ToString();
            int    grade     = int.Parse(jObjRecv["grade"].ToString());

            //参数验证
            if (show_id.Trim().Length == 0)
            {
                return;
            }
            if (token.Trim().Length == 0)
            {
                return;
            }
            if (game_name.Length == 0)
            {
                return;
            }

            var dbLink = Program.dbSvc.GetLink(workerIndex);

            if (!CheckToken(dbLink, show_id, token))
            {
                Program.server.SendError(session, cmd, "token非法或已过期");
                return;
            }

            GameInfo gameInfo = GetGameInfo(game_name);

            if (gameInfo == null)
            {
                Program.server.SendError(session, cmd, "未找到该游戏");
                return;
            }

            if (grade < 0 || grade >= gameInfo.roomGrades.Length)
            {
                Program.server.SendError(session, cmd, "未找到该场次");
                return;
            }

            RoomGrade roomGrade = gameInfo.roomGrades[grade];

            long money = Program.dbHelper.GetUserMoney(dbLink, show_id);

            if (money < roomGrade.moneyLimit)
            {
                Program.server.SendError(session, cmd, "入场金币限制");
                return;
            }

            foreach (var room in roomGrade.rooms)
            {
                Table table = room.AllotTable();

                //该房间全满了
                if (table == null)
                {
                    continue;
                }

                session.TableId = table.id;

                JObject jObj = new JObject();

                jObj["cmd"]      = cmd;
                jObj["ret_code"] = 0;
                jObj["table_id"] = table.id;

                Program.server.Send(session, jObj);
                return;
            }

            Program.server.SendError(session, cmd, "未找到合适的桌子");
        }
Esempio n. 13
0
 public void OnAccepted(int workerIndex, GameServerSession session)
 {
 }
Esempio n. 14
0
        public void OnClosed(int workerIndex, GameServerSession session, string closedCause, bool isInternalCause)
        {
            //Console.WriteLine("{0}:{1}", session.sessionID, closedCause);

            gameModule.OnClosed(workerIndex, session, closedCause, isInternalCause);
        }
Esempio n. 15
0
 public void OnAccepted(int workerIndex, GameServerSession session)
 {
     gameModule.OnAccepted(workerIndex, session);
 }