예제 #1
0
        //设置已充值标记
        public void SetPayTag(String account)
        {
            PackUpdatePayRecInfo pack = new PackUpdatePayRecInfo();

            pack.account = account;
            DBServer.Instance().GetDBClient().SendData(pack.GetBuffer());
        }
예제 #2
0
        //创建军团
        public void CreateLegion(int player_id, String legion_name, String leader_name, byte title, long money, String notice)
        {
            //已经创建军团的过程中,返回
            for (int i = 0; i < mListTemp.Count; i++)
            {
                if (mListTemp[i].leader_id == player_id)
                {
                    return;
                }
            }
            LegionOption option = new LegionOption();

            option.SetCreateTag();
            option.player_id         = player_id;
            option.mInfo.leader_id   = player_id;
            option.mInfo.leader_name = leader_name;
            option.mInfo.name        = legion_name;
            option.mInfo.money       = money;
            option.mInfo.notice      = notice;
            DBServer.Instance().GetDBClient().SendData(option.GetBuffer());

            LegionInfo info = new LegionInfo();

            info.leader_id   = player_id;
            info.name        = legion_name;
            info.leader_name = leader_name;
            info.money       = money;
            info.notice      = notice;
            mListTemp.Add(info);
        }
예제 #3
0
 public static DBServer Instance()
 {
     if (m_Intsance == null)
     {
         m_Intsance = new DBServer();
     }
     return(m_Intsance);
 }
예제 #4
0
 public static DBServer Instance()
 {
     if (m_Intsance == null)
     {
         m_Intsance = new DBServer();
     }
     return m_Intsance;
 }
예제 #5
0
 public void DB_Update(PlayerObject play)
 {
     //发给dbserver 更新爵位信息
     GameBase.Network.Internal.UPDATEGUANJUEDATA updatedb = new GameBase.Network.Internal.UPDATEGUANJUEDATA();
     updatedb.info.id      = (uint)play.GetBaseAttr().player_id;
     updatedb.info.name    = play.GetName();
     updatedb.info.guanjue = play.GetBaseAttr().guanjue;
     DBServer.Instance().GetDBClient().SendData(updatedb.GetBuffer());
 }
예제 #6
0
        static void Main(string[] args)
        {
            //FileStream f = new FileStream("E:\\soul\\trunk\\MapServer\\verpack.dat",FileMode.Open);
            //byte[] ret = new byte[f.Length];
            //f.Read(ret, 0, (int)f.Length);
            //f.Close();
            //ConfigManager.Instance().GetVerPacket().InitPacket(ret);
            if (!GameServer.Start())
            {
                return;
            }
            //初始化连接dbserver
            DBServer.Instance().Init();
            //工作逻辑线程
            Thread logicThread = new Thread(new ThreadStart(ServerRun));

            logicThread.IsBackground = true;
            logicThread.Start();
            while (true)
            {
                String   sCommand = Console.ReadLine();
                String[] sArr     = sCommand.Split(' ');
                if (sArr.Length <= 0)
                {
                    continue;
                }
                sCommand = sArr[0];
                try
                {
                    if (sCommand == "quit" || sCommand == "exit")
                    {
                        break;
                    }
                    if (sCommand == "test")
                    {
                        PlayerObject       play = MapManager.Instance().GetGameMapToID(1000).GetObject(3988) as PlayerObject;
                        NetMsg.MsgUpdateSP data = new NetMsg.MsgUpdateSP();
                        data.Create(null, play.GetGamePackKeyEx());
                        data.role_id = play.GetTypeId();
                        data.value   = Convert.ToUInt32(sArr[1]);
                        data.sp      = Convert.ToUInt32(sArr[2]);
                        play.SendData(data.GetBuffer());
                    }
                }
                catch (System.Exception ex)
                {
                    Log.Instance().WriteLog(ex.Message);
                }
            }
            GameServer.Stop();
            Log.Instance().WriteLog("exit server!");

            Console.ReadLine();
        }
예제 #7
0
 public void DB_Save()
 {
     GameBase.Network.Internal.ROLEDATA_FRIEND info = new GameBase.Network.Internal.ROLEDATA_FRIEND();
     info.playerid = play.GetBaseAttr().player_id;
     info.SetSaveTag();
     for (int i = 0; i < mList.Count; i++)
     {
         info.list_item.Add(mList[i]);
     }
     DBServer.Instance().GetDBClient().SendData(info.GetBuffer());
 }
예제 #8
0
        public static void LogicRun()
        {
            SocketCallBack.Instance().Run();           //玩家发过来的封包进行处理,加到数据队列
            DBServer.Instance().ProcessDBNetMsg();     //优先处理db数据库服务器发过来的消息
            SessionManager.Instance().ProcessNetMsg(); //处理玩家发过来的消息
            MapManager.Instance().Process();
            UserEngine.Instance().Run();
            ScriptTimerManager.Instance().Run(); //脚本定时器

            WorldPigeon.Instance().Run();        //魔法飞鸽
        }
예제 #9
0
        public void UpdateLegionInfo(uint legion_id, int player_id)
        {
            if (!mDicLegion.ContainsKey(legion_id))
            {
                return;
            }
            Legion info = mDicLegion[legion_id];

            //发送给dbserver 更新军团数据
            LegionOption option = new LegionOption();

            option.SetUpdateTag();
            option.player_id = player_id;
            option.mInfo     = info.GetBaseInfo();
            DBServer.Instance().GetDBClient().SendData(option.GetBuffer());
        }
예제 #10
0
 public void Run()
 {
     //这里可以根据服务器的压力要不要延迟数据库
     //下次再写
     if (mListSaveRole.Count > 0)
     {
         DBServer.Instance().SaveRoleData(mListSaveRole[0]);
         mListSaveRole.RemoveAt(0);
     }
     //缓存队列保存时间
     if (DBServer.Instance().IsConnect() && mListCacheRole.Count > 0)
     {
         if (System.Environment.TickCount - mnCachePlaySaveTick > 5000) //五秒保存一次玩家数据
         {
             Log.Instance().WriteLog("保存玩家缓冲队列,玩家昵称:" + mListCacheRole[0].GetName());
             mnCachePlaySaveTick = System.Environment.TickCount;
             DBServer.Instance().SaveRoleData(mListCacheRole[0]);
             mListCacheRole.RemoveAt(0);
         }
     }
 }
예제 #11
0
        public void DB_Save()
        {
            if (mDicMagic.Count <= 0)
            {
                return;
            }
            GameBase.Network.Internal.RoleData_Magic magic = new GameBase.Network.Internal.RoleData_Magic();
            magic.SetSaveTag();
            magic.ownerid = play.GetBaseAttr().player_id;
            foreach (GameStruct.RoleMagicInfo info in mDicMagic.Values)
            {
                GameBase.Network.Internal.MagicInfo item = new GameBase.Network.Internal.MagicInfo();
                item.id      = info.id;
                item.magicid = info.magicid;
                item.level   = info.level;
                item.exp     = info.exp;
                magic.mListMagic.Add(item);
            }

            DBServer.Instance().GetDBClient().SendData(magic.GetBuffer());
        }
예제 #12
0
        public void ProcessNetMsg()
        {
            foreach (GameSession session in m_DicSession.Values)
            {
                if (session == null || session.m_GamePack == null)
                {
                    continue;
                }
                byte[] retdata = session.m_GamePack.GetData();
                if (retdata != null)
                {
                    GameBase.Network.PackIn packin = new GameBase.Network.PackIn(retdata);
                    PlayerObject            play   = UserEngine.Instance().FindPlayerObjectToID(session.gameid);
                    ushort tag = packin.ReadUInt16();
                    if (play != null)
                    {
                        play.ProcessNetMsg(tag, retdata);
                        continue;
                    }
                    //第一次的封包一定是更新key哒..
                    if (play == null && tag != PacketProtoco.C_UPDATEKEY && tag != PacketProtoco.C_QUERYCREATEROLENAME &&
                        tag != PacketProtoco.C_CREATEROLE)
                    {
                        continue;
                    }

                    switch (tag)
                    {
                    case PacketProtoco.C_UPDATEKEY:
                    {
                        int            key      = packin.ReadInt32();
                        int            key2     = packin.ReadInt32();
                        TempPlayObject tempplay = UserEngine.Instance().GetTempPlayObj(key, key2);
                        if (tempplay == null)
                        {
                            return;                               //没有经过loginsserver进入的非法封包
                        }
                        tempplay.play.SetGameSession(session);
                        session.GetGamePackKeyEx().SunUpdateKey(key, key2);
                        NetMsg.MsgNotice msgNotice;
                        //没有角色就创建角色
                        if (!tempplay.isRole)
                        {
                            msgNotice = new NetMsg.MsgNotice();
                            msgNotice.Create(null, session.GetGamePackKeyEx());
                            session.SendData(msgNotice.GetCreateRoleBuff());
                            return;
                        }
                        //有角色就进游戏
                        UserEngine.Instance().RemoveTempPlayObject(tempplay.play.GetGameID());
                        tempplay.play.EnterGame(session);
                        break;
                    }

                    case PacketProtoco.C_QUERYCREATEROLENAME:           //创建角色名查询
                    {
                        NetMsg.MsgQueryCreateRoleName info = new NetMsg.MsgQueryCreateRoleName();
                        info.Create(retdata, null);
                        int key = 0, key2 = 0;
                        session.GetGamePackKeyEx().GetKey(ref key, ref key2);
                        TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(key, key2);
                        if (temp == null)
                        {
                            Log.Instance().WriteLog("找到玩家对象-在ProcessNetMsg code:1");
                            break;
                        }

                        //发给dbserver 查询
                        GameBase.Network.Internal.QueryRoleName query = new GameBase.Network.Internal.QueryRoleName();
                        query.gameid = temp.play.GetGameID();
                        query.name   = info.GetName();

                        DBServer.Instance().GetDBClient().SendData(query.GetBuffer());

                        //NetMsg.MsgNotice notice = new NetMsg.MsgNotice();
                        //notice.Create(null, session.GetGamePackKeyEx());
                        //session.SendData(notice.GetQueryNameBuff());
                        break;
                    }

                    case PacketProtoco.C_CREATEROLE:            //创建角色
                    {
                        int key = 0, key2 = 0;
                        session.GetGamePackKeyEx().GetKey(ref key, ref key2);
                        TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(key, key2);
                        if (temp == null)
                        {
                            Log.Instance().WriteLog("找到玩家对象-在ProcessNetMsg code:2");
                            break;
                        }
                        NetMsg.MsgCreateRoleInfo info = new NetMsg.MsgCreateRoleInfo();
                        info.Create(retdata, null);
                        if (info.GetName().Length <= 0)
                        {
                            Log.Instance().WriteLog("角色名称为空!!");
                            break;
                        }
                        PlayerObject _play = temp.play;
                        _play.SetGameSession(session);

                        _play.SetName(info.GetName());
                        _play.GetBaseAttr().profession = (byte)info.profession;
                        _play.GetBaseAttr().lookface   = info.lookface;


                        //发给dbserver
                        GameBase.Network.Internal.CreateRole create = new GameBase.Network.Internal.CreateRole();
                        create.accountid  = temp.accountid;
                        create.lookface   = info.lookface;
                        create.name       = info.GetName();
                        create.profession = (byte)info.profession;
                        create.gameid     = temp.play.GetGameID();
                        DBServer.Instance().GetDBClient().SendData(create.GetBuffer());
                        //测试游戏
                        //play = new PlayerObject();
                        //play.mapid = 1000;
                        //play.mPoint.x = 400;
                        //play.mPoint.y = 440;
                        //session.gameid = play.GetGameID();
                        //MapManager.Instance().GetGameMapToID(play.mapid).AddObject(play, session);
                        //UserEngine.Instance().AddPlayerObject(play);

                        ////公告信息
                        //NetMsg.MsgNotice msgNotice = new NetMsg.MsgNotice();
                        //msgNotice.Create(null, session.GetGamePackKeyEx());
                        //session.SendData(msgNotice.GetStartGameBuff());
                        //byte[] roledata = {238, 3, 64, 66, 15, 0, 241, 73, 2, 0, 101,
                        //      0, 0, 0, 60, 1, 0, 0, 0, 0, 0, 0, 81, 118,
                        //      203, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      31, 1, 0, 0, 73, 0, 0, 0, 30, 0, 100, 0, 99,
                        //      0, 102, 0, 0, 0, 202, 3, 222, 3, 134, 7, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 255, 10, 0, 0, 1, 0, 0,
                        //      0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 12, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 20, 0, 4, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 105,
                        //      0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        //      0, 0, 0, 0, 2, 8, 102, 101, 111, 119, 102, 113, 101, 119, 2,
                        //      206, 222, 0, 0, 0 };
                        ////session.GetGamePackKeyEx().EncodePacket(ref roledata, roledata.Length);
                        ////session.SendData(roledata);
                        ////
                        //NetMsg.MsgSelfRoleInfo rolemsg = new NetMsg.MsgSelfRoleInfo();
                        //rolemsg.Create(roledata, session.GetGamePackKeyEx());
                        //rolemsg.roletype = 140001;
                        //rolemsg.roleid = play.GetTypeId();
                        //rolemsg.name = "测试角色" + play.GetTypeId().ToString();
                        //play.Name = rolemsg.name;
                        //session.SendData(rolemsg.GetBuffer());


                        ////测试增加装备 测试装备
                        //NetMsg.MsgItemInfo item = new NetMsg.MsgItemInfo();
                        //item.Create(null, session.GetGamePackKeyEx());
                        //item.postion = NetMsg.MsgItemInfo.ITEMPOSITION_ARMOR;
                        //item.id = 112434;
                        //item.item_id = 135114;
                        //item.amount = item.amount_limit = 1;
                        //session.SendData(item.GetBuffer());
                        ////测试武器
                        //item = new NetMsg.MsgItemInfo();
                        //item.Create(null, session.GetGamePackKeyEx());
                        //item.postion = NetMsg.MsgItemInfo.ITEMPOSITION_WEAPONR;
                        //item.id = 112435;
                        //item.item_id = 440244;
                        //item.amount = item.amount_limit = 1;
                        //session.SendData(item.GetBuffer());



                        //NetMsg.MsgUpdateSP sp = new NetMsg.MsgUpdateSP();
                        //sp.Create(null, session.GetGamePackKeyEx());
                        //sp.role_id = play.GetTypeId();
                        //sp.value = 37;
                        //sp.sp = 100;
                        //session.SendData(sp.GetBuffer());

                        //sp = new NetMsg.MsgUpdateSP();
                        //sp.Create(null, session.GetGamePackKeyEx());
                        //sp.role_id = play.GetTypeId();
                        //session.SendData(sp.GetBuffer());


                        ////测试新增技能
                        //ushort[] skill = { 3011 };//, 3002, 1010, 3005, 3009, 8003
                        //for (int i = 0; i < skill.Length; i++)
                        //{
                        //    NetMsg.MsgMagicInfo magicinfo = new NetMsg.MsgMagicInfo();
                        //    magicinfo.Create(null, session.GetGamePackKeyEx());
                        //    magicinfo.id = play.GetTypeId();
                        //    magicinfo.magicid = skill[i];
                        //    magicinfo.level = 2;
                        //    session.SendData(magicinfo.GetBuffer());
                        //}



                        ////进入地图
                        //NetMsg.MsgMapInfo mapinfo = new NetMsg.MsgMapInfo();
                        //mapinfo.Create(null, session.GetGamePackKeyEx());
                        //mapinfo.Init(play.mapid, play.mPoint.x, play.mPoint.y);
                        //session.SendData(mapinfo.GetBuffer());



                        ////刷新可视列表;

                        //play.RefreshVisibleObject();
                        //GameStruct.Action act = new GameStruct.Action(GameStruct.Action.MOVE);
                        //play.PushAction(act);
                        break;
                    }
                    }
                }
            }
        }