Instance() public static method

public static Instance ( ) : UserEngine
return UserEngine
コード例 #1
0
ファイル: UserEngine.cs プロジェクト: tangfengray/soul
        //广播文字消息
        public void BroadcastMsg(GameBase.Config.BROADCASTMSGTYPE type, String msg)
        {
            foreach (PlayerObject obj in m_DicPlayerObject.Values)
            {
                if (obj.GetGameSession() != null)
                {
                    switch (type)
                    {
                    case GameBase.Config.BROADCASTMSGTYPE.LEFT:
                    {
                        obj.LeftNotice(msg);
                        break;
                    }

                    case GameBase.Config.BROADCASTMSGTYPE.CHAT:
                    {
                        obj.ChatNotice(msg);
                        break;
                    }

                    case GameBase.Config.BROADCASTMSGTYPE.SCREEN:
                    {
                        UserEngine.Instance().SceneNotice(msg);
                        break;
                    }
                    }
                }
            }
        }
コード例 #2
0
ファイル: GameMap.cs プロジェクト: tangfengray/soul
        //广播文字消息
        public void BroadcastMsg(GameBase.Config.BROADCASTMSGTYPE type, String msg)
        {
            foreach (BaseObject obj in mDicObject.Values)
            {
                if (obj.type != OBJECTTYPE.PLAYER)
                {
                    continue;
                }
                PlayerObject play = obj as PlayerObject;
                if (obj.GetGameSession() != null)
                {
                    switch (type)
                    {
                    case GameBase.Config.BROADCASTMSGTYPE.LEFT:
                    {
                        play.LeftNotice(msg);
                        break;
                    }

                    case GameBase.Config.BROADCASTMSGTYPE.CHAT:
                    {
                        play.ChatNotice(msg);
                        break;
                    }

                    case GameBase.Config.BROADCASTMSGTYPE.SCREEN:
                    {
                        UserEngine.Instance().SceneNotice(msg);
                        break;
                    }
                    }
                }
            }
        }
コード例 #3
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
        //删除好友
        public void DeleteFriend(uint playerid, bool deleteparty = true)
        {
            RoleData_Friend friend = null;

            for (int i = 0; i < mList.Count; i++)
            {
                if (mList[i].friendid == playerid)
                {
                    friend = mList[i];
                    break;
                }
            }


            play.LeftNotice(string.Format("由于彼此间的友谊出现了无法修复的裂痕,【{0}】决定与【{1}】断绝好友关系", play.GetName(), friend.friendname));
            friend.id = -1;
            SendFriendInfo(friend, NetMsg.MsgFriendInfo.TYPE_KILL);
            if (deleteparty)
            {
                PlayerObject target = UserEngine.Instance().FindPlayerObjectToPlayerId((int)playerid);
                if (target == null)
                {
                    return;
                }
                target.GetFriendSystem().DeleteFriend((uint)play.GetBaseAttr().player_id, false);
            }
        }
コード例 #4
0
ファイル: UserEngine.cs プロジェクト: tangfengray/soul
 //屏幕中间公告
 public void SceneNotice(String text)
 {
     NetMsg.MsgNotice notice = new NetMsg.MsgNotice();
     notice.Create(null, null);
     byte[] buff = notice.GetSceneNoticeBuff(text);
     UserEngine.Instance().BrocatBuffer(buff);
 }
コード例 #5
0
        //发送飞鸽信息
        private void Send(PigeonInfo info)
        {
            short msgLen = 28;

            msgLen += (short)(Coding.GetDefauleCoding().GetBytes(info.name).Length + 1);
            msgLen += 17;
            msgLen += (short)(Coding.GetDefauleCoding().GetBytes(info.text).Length + 1);
            GameBase.Network.PacketOut outpack = new GameBase.Network.PacketOut();
            outpack.WriteInt16(msgLen);
            outpack.WriteInt16(1004);
            outpack.WriteInt32(0xffffff);
            outpack.WriteInt32(2017);
            outpack.WriteInt32(1419);
            outpack.WriteInt32(-1);
            outpack.WriteInt32(0);
            outpack.WriteByte(4); //四个字符串数组
            outpack.WriteString(info.name);
            outpack.WriteString("ALLUSERS");
            outpack.WriteString("1241350");
            outpack.WriteString(info.text);
            outpack.WriteByte(0);
            outpack.WriteByte(0);
            outpack.WriteByte(0);
            UserEngine.Instance().BrocatBuffer(outpack.Flush());
        }
コード例 #6
0
        //发送爵位被改变的文字消息,全服广播
        public void SendChangeGuanJueMsg(PlayerObject play, GameStruct.GUANGJUELEVEL lv)
        {
            String str = "";

            switch (lv)
            {
            case GameStruct.GUANGJUELEVEL.KING:
            {
                str = string.Format("这一天将载入永恒的史册,玩家[{0}]赢得了至高无上的光荣与祝福,登上了国王的宝座!", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.SCREEN, str);
                break;
            }

            case GameStruct.GUANGJUELEVEL.QUEEN:
            {
                str = string.Format("这是万众曙目的时刻![{0}]戴上了神圣的王冠,让我们为新的卡诺萨城女王欢呼喝彩吧!", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.SCREEN, str);
                break;
            }

            case GameStruct.GUANGJUELEVEL.DUKE:
            {
                str = string.Format("卡诺萨城的钟声轰然响起,[{0}]为王国做出来重大贡献,欶封为皇家公爵!", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.SCREEN, str);
                break;
            }

            case GameStruct.GUANGJUELEVEL.MARQUIS:
            {
                str = string.Format("光荣的号角响起,[{0}]受封为皇家候爵,愿他的荣耀之旗永闪光芒!", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.SCREEN, str);
                break;
            }

            case  GameStruct.GUANGJUELEVEL.EARL:
            {
                str = string.Format("恭祝玩家[{0}]受封为伯爵,庆祝的歌声将响彻全城,他的名字将与卡诺萨城同在", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.CHAT, str);
                break;
            }

            case  GameStruct.GUANGJUELEVEL.VISCOUNT:
            {
                str = string.Format("恭祝玩家[{0}]受封为子爵,在神圣的光芒下,让我们共同见证这份光荣!", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.CHAT, str);
                break;
            }

            case GameStruct.GUANGJUELEVEL.LORD:
            {
                str = string.Format("祝贺玩家[{0}]晋升为勋爵,卡诺萨城有多了一位尊贵的守护者。", play.GetName());
                UserEngine.Instance().BroadcastMsg(BROADCASTMSGTYPE.CHAT, str);
                break;
            }
            }
        }
コード例 #7
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
        //拒绝添加好友请求
        public void RefuseFriend(uint playerid)
        {
            PlayerObject target = UserEngine.Instance().FindPlayerObjectToPlayerId((int)playerid);

            if (target == null)
            {
                return;
            }
            target.LeftNotice("对方拒绝你的好友请求。");
        }
コード例 #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
ファイル: PlayerTrad.cs プロジェクト: tangfengray/soul
        public void SetTrading(bool v)
        {
            mIsTrad = v;
            PacketOut outpack = null;

            if (mIsTrad)
            {
                PlayerObject target = UserEngine.Instance().FindPlayerObjectToTypeID(GetTradTarget());
                if (target == null)
                {
                    SetTrading(false);
                    return;
                }
                outpack = new PacketOut(target.GetGamePackKeyEx());
                outpack.WriteUInt16(16);
                outpack.WriteUInt16(1056);
                outpack.WriteUInt32(play.GetTypeId());

                outpack.WriteUInt32(3);
                outpack.WriteUInt32(1);
                target.SendData(outpack.Flush());
            }
            else
            {
                byte[] data = { 16, 0, 32, 4, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0 };
                outpack = new PacketOut(play.GetGamePackKeyEx());
                outpack.WriteBuff(data);
                play.SendData(outpack.Flush());
                play.LeftNotice("交易失败!");

                //返还魔石、金币 道具与装备
                play.ChangeAttribute(GameStruct.UserAttribute.GOLD, mnGold);
                if (mnGameGold > 0)
                {
                    play.ChangeAttribute(GameStruct.UserAttribute.GAMEGOLD, mnGameGold);
                }
                if (mnGold > 0)
                {
                    play.ChangeAttribute(GameStruct.UserAttribute.GOLD, mnGameGold);
                }
                //装备
                for (int i = 0; i < mListItem.Count; i++)
                {
                    play.GetItemSystem().AddTradItem(mListItem[i]);
                }
                //返还幻兽
                for (int i = 0; i < mListEudemon.Count; i++)
                {
                    play.GetEudemonSystem().AddEudemon(mListEudemon[i]);
                }
                mListItem.Clear();
                mListEudemon.Clear();
            }
        }
コード例 #10
0
ファイル: DBServer.cs プロジェクト: tangfengray/soul
        //发送玩家数据信息到dbserver 保存到数据库
        //play 玩家对象
        //isExit 是否是退出游戏 -
        public void SaveRoleData(PlayerObject play, bool isExit = false)
        {
            if (!this.IsConnect())
            {
                UserEngine.Instance().AddCachePlay(play);
                Log.Instance().WriteLog("保存玩家数据失败,dbserver未连接,已加入到数据库缓冲存储区");
                return;
            }
            //人物基本属性
            SaveRoleData_Attr data = new SaveRoleData_Attr();

            GameStruct.PlayerAttribute attr = play.GetBaseAttr();

            data.accountid  = attr.account_id;
            data.IsExit     = isExit;
            data.name       = play.GetName();
            data.lookface   = attr.lookface;
            data.hair       = attr.hair;
            data.level      = (byte)attr.level;
            data.exp        = attr.exp;
            data.life       = attr.life;
            data.mana       = attr.mana;
            data.profession = attr.profession;
            data.pk         = attr.pk;
            data.gold       = attr.gold;
            data.gamegold   = attr.gamegold;
            data.stronggold = attr.stronggold;
            data.godlevel   = attr.godlevel;
            data.maxeudemon = attr.maxeudemon;
            if (play.GetGameMap() == null)
            {
                data.mapid = 1000;
                data.x     = 145;
                data.y     = 413;
            }
            else
            {
                data.mapid = play.GetGameMap().GetMapInfo().id;
                data.x     = play.GetCurrentX();
                data.y     = play.GetCurrentY();
            }

            data.hotkey  = play.GetHotKeyInfo();
            data.guanjue = attr.guanjue;
            GetDBClient().SendData(data.GetBuffer());
            //保存道具信息
            play.GetItemSystem().DB_Save();
            //保存技能信息
            play.GetMagicSystem().DB_Save();
            //保存幻兽信息
            play.GetEudemonSystem().DB_Save();
            //好友信息
            play.GetFriendSystem().DB_Save();
        }
コード例 #11
0
ファイル: PlayerTrad.cs プロジェクト: tangfengray/soul
        //请求交易
        public void RequstTrad(NetMsg.MsgTradInfo info)
        {
            PlayerObject obj = UserEngine.Instance().FindPlayerObjectToTypeID(info.typeid);

            if (obj == null)
            {
                play.LeftNotice("对方已离线,无法交易!");
                return;
            }
            if (play.GetTimerSystem().QueryStatus(GameStruct.RoleStatus.STATUS_PTICH) != null)
            {
                play.MsgBox("摆摊中无法交易!");
                return;
            }
            if (obj.GetTimerSystem().QueryStatus(GameStruct.RoleStatus.STATUS_PTICH) != null)
            {
                play.MsgBox("对方摆摊中,无法交易!");
                return;
            }
            if (this.GetTradTarget() == info.typeid) //同意交易
            {
                obj.GetTradSystem().SetTrading(true);
                play.GetTradSystem().SetTrading(true);
                return;
            }
            else if (this.GetTradTarget() != 0)//正在交易中- 无法再次交易
            {
                play.LeftNotice("正在交易中,无法再次交易");
                return;
            }

            //请求交易
            //距离判断
            int x = Math.Abs(play.GetCurrentX() - obj.GetCurrentX());
            int y = Math.Abs(play.GetCurrentY() - obj.GetCurrentY());

            if (x > GameBase.Config.Define.MAX_PLAY_VISIBLE_DISTANCE ||
                y > GameBase.Config.Define.MAX_PLAY_VISIBLE_DISTANCE)
            {
                play.LeftNotice("距离太远,无法交易");
                return;
            }
            NetMsg.MsgTradInfo data = new NetMsg.MsgTradInfo();
            data.Create(null, obj.GetGamePackKeyEx());
            data.typeid     = play.GetTypeId();
            data.type       = NetMsg.MsgTradInfo.REQUEST_TRAD;
            data.level      = play.GetBaseAttr().level;
            data.fightpower = (short)play.GetFightSoul();
            obj.SendData(data.GetBuffer());
            obj.GetTradSystem().SetTradTarget(play.GetTypeId());
            play.GetTradSystem().SetTradTarget(obj.GetTypeId());
            play.LeftNotice("[交易]已经发出交易请求。");
        }
コード例 #12
0
ファイル: SocketCallBack.cs プロジェクト: tangfengray/soul
        public void Run()
        {
            int runtime = System.Environment.TickCount;

            while (true)
            {
                if (System.Environment.TickCount - runtime > 300)
                {
                    break;                                              //超出三百毫秒下次再处理
                }
                SocketInfo info = GetInfo();
                if (info == null)
                {
                    break;
                }
                if (info.s == null)
                {
                    break;
                }
                Socket s = info.s;
                switch (info.type)
                {
                case TYPE_ONCONNECT:
                {
                    SessionManager.Instance().AddSession(s, GameServer.GetTcpServer());
                    break;
                }

                case TYPE_CLOSE:
                {
                    PlayerObject play = UserEngine.Instance().FindPlayerObjectToSocket(s);
                    SessionManager.Instance().RemoveSession(s);
                    UserEngine.Instance().RemovePlayObject(play);
                    //if (play != null)
                    // {
                    // play.GetGameSession().Dispose();
                    // play.SetGameSession(null);
                    //}

                    break;
                }

                case TYPE_RECEIVE:
                {
                    SessionManager.Instance().AddNetData(s, info.data, info.data.Length);
                    break;
                }
                }
            }
        }
コード例 #13
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
        public void SendFriendInfo(RoleData_Friend info, byte type = NetMsg.MsgFriendInfo.TYPE_FRIEND)
        {
            NetMsg.MsgFriendInfo data = new NetMsg.MsgFriendInfo();
            data.Create(null, play.GetGamePackKeyEx());
            data.playerid = info.friendid;
            data.type     = type;
            data.name     = info.friendname;
            PlayerObject obj = UserEngine.Instance().FindPlayerObjectToPlayerId((int)info.friendid);

            if (obj != null)
            {
                data.Online     = 1;
                data.level      = obj.GetBaseAttr().level;
                data.fightpower = (uint)obj.GetFightSoul();
            }
            play.SendData(data.GetBuffer());
        }
コード例 #14
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
 //广播所有好友信息
 public void BrocatMsg(byte type)
 {
     for (int i = 0; i < mList.Count; i++)
     {
         PlayerObject obj = UserEngine.Instance().FindPlayerObjectToPlayerId((int)mList[i].friendid);
         if (obj != null)
         {
             NetMsg.MsgFriendInfo data = new NetMsg.MsgFriendInfo();
             data.Create(null, obj.GetGamePackKeyEx());
             data.fightpower = (uint)play.GetFightSoul();
             data.level      = play.GetBaseAttr().level;
             data.playerid   = (uint)play.GetBaseAttr().player_id;
             data.name       = play.GetName();
             data.type       = type;
             obj.SendData(data.GetBuffer());
         }
     }
 }
コード例 #15
0
ファイル: PlayerTrad.cs プロジェクト: tangfengray/soul
        //取消交易
        public void QuitTrad(NetMsg.MsgTradInfo info)
        {
            if (GetTradTarget() == 0)
            {
                return;
            }
            this.SetTrading(false);
            this.SetSureTradTag(false);
            PlayerObject obj = UserEngine.Instance().FindPlayerObjectToTypeID(GetTradTarget());

            if (obj == null)
            {
                return;
            }
            this.SetTradTarget(0);
            obj.GetTradSystem().SetTradTarget(0);
            obj.GetTradSystem().SetTrading(false);
            obj.GetTradSystem().SetSureTradTag(false);
        }
コード例 #16
0
        //创建军团返回
        public void CreateLegion_Ret(CreateLegion_Ret info)
        {
            LegionInfo le = null;

            for (int i = 0; i < mListTemp.Count; i++)
            {
                if (mListTemp[i].leader_id == info.play_id)
                {
                    le    = mListTemp[i];
                    le.id = (uint)info.legion_id;
                    mListTemp.Remove(le);
                    break;
                }
            }
            if (info == null || info.ret == 0 || le == null)
            {
                return;
            }
            PlayerObject play = UserEngine.Instance().FindPlayerObjectToPlayerId(info.play_id);

            if (play == null)
            {
                return;
            }

            //加入军团长
            LegionMember member = new LegionMember();

            member.boChange     = true;
            member.members_name = play.GetName();
            member.money        = info.money;
            member.id           = info.boss_id;
            member.rank         = GameBase.Config.Define.LEGION_PLACE_JUNTUANZHANG;
            le.list_member.Add(member);



            Legion l = new Legion();

            l.SetBaseInfo(le);
            mDicLegion[le.id] = l;
            play.GetLegionSystem().SetLegion(l, true);
        }
コード例 #17
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
        // public void SetFriendTarget(uint typeid)
        // {
        //     mTargetId = typeid;
        // }
        //public uint GetFriendTarget() { return mTargetId; }
        //添加好友
        public void AddFriend(uint playerid, byte type, bool party = true)
        {
            PlayerObject target = UserEngine.Instance().FindPlayerObjectToPlayerId((int)playerid);

            if (target == null)
            {
                return;
            }
            for (int i = 0; i < mList.Count; i++)
            {
                if (mList[i].friendid == (uint)target.GetBaseAttr().player_id&&
                    mList[i].friendtype == type)
                {
                    if (mList[i].id != -1) //删除标识
                    {
                        return;
                    }
                    else
                    {
                        mList.RemoveAt(i);
                        break;
                    }
                }
            }

            play.LeftNotice(string.Format("{0},{1}锸血为盟,宣誓从此将生死与共,永不背叛!", play.GetName(), target.GetName()));

            RoleData_Friend friend = new RoleData_Friend();

            friend.id         = 0;
            friend.friendid   = (uint)target.GetBaseAttr().player_id;
            friend.friendtype = type;
            friend.friendname = target.GetName();
            mList.Add(friend);
            SendFriendInfo(friend);

            if (party)
            {
                target.GetFriendSystem().AddFriend((uint)play.GetBaseAttr().player_id, type, false);
            }
        }
コード例 #18
0
ファイル: PlayerTrad.cs プロジェクト: tangfengray/soul
        //确定交易
        public void SureTrad()
        {
            PlayerObject obj = UserEngine.Instance().FindPlayerObjectToTypeID(GetTradTarget());

            if (obj == null)
            {
                return;
            }
            play.GetTradSystem().SetSureTradTag(true);
            //通知对方已经确定交易了--
            byte[] data = { 16, 0, 32, 4, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0 };
            obj.GetGamePackKeyEx().EncodePacket(ref data, data.Length);
            obj.SendData(data);

            if (!obj.GetTradSystem().GetSureTradTag()) //对方还没确定交易
            {
                return;
            }
            obj.GetTradSystem().Trad(play);
            play.GetTradSystem().Trad(obj);
        }
コード例 #19
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
        //请求加为好友
        public void RequestAddFriend(NetMsg.MsgFriendInfo info)
        {
            PlayerObject target = UserEngine.Instance().FindPlayerObjectToTypeID(info.playerid);

            if (target == null)
            {
                play.LeftNotice("对方已离线,无法添加好友!");
                return;
            }
            if (mList.Count >= MAX_FRIEND_COUNT)
            {
                play.LeftNotice("阁下好友人数已满,无法再次添加!");
                return;
            }
            for (int i = 0; i < mList.Count; i++)
            {
                if (mList[i].friendid == target.GetBaseAttr().player_id)
                {
                    play.ChatNotice(string.Format("{0}已经是你的好友了!", mList[i].friendname));
                    return;
                }
            }
            //发给被请求玩家
            NetMsg.MsgFriendInfo data = new NetMsg.MsgFriendInfo();
            data.Create(null, target.GetGamePackKeyEx());
            data.playerid   = (uint)play.GetBaseAttr().player_id;
            data.fightpower = (uint)play.GetFightSoul();
            data.type       = NetMsg.MsgFriendInfo.TYPE_ADDFRIEND;
            data.Online     = 1;
            data.level      = play.GetBaseAttr().level;
            data.name       = play.GetName();
            target.SendData(data.GetBuffer());
            // target.GetFriendSystem().SetFriendTarget(play.GetTypeId()) ;
            play.LeftNotice("已经发送结为好友的请求");
            target.LeftNotice(string.Format("血与火的洗礼证明了坚固的友谊,{0}对你报以信任的眼神,你是否接受?", play.GetName()));
        }
コード例 #20
0
ファイル: PlayerFriend.cs プロジェクト: tangfengray/soul
        public void GetFriendInfo(int playerid)
        {
            PlayerObject obj = UserEngine.Instance().FindPlayerObjectToPlayerId(playerid);

            if (obj == null)
            {
                return;
            }

            GameBase.Network.PacketOut outpack = new GameBase.Network.PacketOut(play.GetGamePackKeyEx());
            outpack.WriteUInt16(52);
            outpack.WriteUInt16(2033);
            outpack.WriteInt32(playerid);
            outpack.WriteUInt32(obj.GetBaseAttr().lookface);
            outpack.WriteByte(obj.GetBaseAttr().level);
            outpack.WriteByte(obj.GetBaseAttr().profession); //职业
            outpack.WriteInt32(0);
            outpack.WriteInt16(0);
            outpack.WriteByte(206);
            outpack.WriteByte(222);
            byte[] data = new byte[30];
            outpack.WriteBuff(data);
            play.SendData(outpack.Flush());
        }
コード例 #21
0
ファイル: PlayerTrad.cs プロジェクト: tangfengray/soul
        public void SetTradGameGold(int gamegold)
        {
            if (gamegold <= 0)
            {
                return;
            }
            PlayerObject obj = UserEngine.Instance().FindPlayerObjectToTypeID(GetTradTarget());

            if (obj == null)
            {
                return;
            }
            mnGameGold = gamegold;

            //发给对方
            PacketOut outpack = new PacketOut(obj.GetGamePackKeyEx());

            outpack.WriteUInt16(16);
            outpack.WriteUInt16(1056);
            outpack.WriteInt32(mnGameGold);
            outpack.WriteInt32(12);
            outpack.WriteInt32(0);
            obj.SendData(outpack.Flush());
        }
コード例 #22
0
ファイル: DBServer.cs プロジェクト: tangfengray/soul
        public void ProcessDBNetMsg()
        {
            if (!mbConnect && System.Environment.TickCount - mnReconnectTick > 5000)//五秒重连
            {
                mTcpDBClient.ReConnect();
                mnReconnectTick = System.Environment.TickCount;
            }
            byte[] buff = null;
            lock (_lock)
            {
                buff = mDBPacket.GetData();
            }

            if (buff == null)
            {
                return;
            }
            PackIn inpack = new PackIn(buff);
            ushort param  = inpack.ReadUInt16();

            switch (param)
            {
            case GameBase.Network.Internal.Define.ROLEINFO:
            {
                GameBase.Network.Internal.RoleInfo roleinfo = new GameBase.Network.Internal.RoleInfo(buff);
                //判断是否有缓存数据-
                PlayerObject cacheplay = UserEngine.Instance().GetCachePlay(roleinfo.sAccount);
                if (cacheplay != null)
                {
                    Log.Instance().WriteLog("检测到角色缓存数据,保存中!" + cacheplay.GetName());
                    UserEngine.Instance().RemoveCachePlay(cacheplay);
                    cacheplay.ExitGame();
                    return;
                }
                UserEngine.Instance().AddTempPlayObject(roleinfo);

                //回发给dbserver 表示收到了角色信息- 让他通知loginserver 发数据给玩家连接mapserver
                GameBase.Network.Internal.RoleInfo_Ret ret = new GameBase.Network.Internal.RoleInfo_Ret();
                ret.gameid    = roleinfo.gameid;
                ret.key       = roleinfo.mKey;
                ret.key2      = roleinfo.mKey1;
                ret.accountid = roleinfo.accountid;
                mTcpDBClient.SendData(ret.GetBuffer());
                Log.Instance().WriteLog("收到临时角色信息:" + roleinfo.sAccount + " id:" + roleinfo.accountid.ToString());
                break;
            }

            case GameBase.Network.Internal.Define.QUERYROLENAME_RET:
            {
                QueryRoleName_Ret ret = new QueryRoleName_Ret();
                ret.Create(buff);
                TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(ret.gameid);
                if (temp == null)
                {
                    Log.Instance().WriteLog("找到玩家对象..在--ProcessDBNetMsg code:2");
                    break;
                }

                NetMsg.MsgNotice notice = new NetMsg.MsgNotice();
                notice.Create(null, temp.play.GetGamePackKeyEx());
                temp.play.SendData(notice.GetQueryNameBuff(!ret.tag));

                break;
            }

            case GameBase.Network.Internal.Define.CREATEROLE_RET:
            {
                CreateRole_Ret ret = new CreateRole_Ret();
                ret.Create(buff);
                TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(ret.gameid);
                if (temp == null)
                {
                    Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:3");
                    break;
                }


                UserEngine.Instance().RemoveTempPlayObject(ret.gameid);         //从临时列表出移除--
                //进入游戏
                temp.play.GetBaseAttr().account_id = temp.accountid;
                temp.play.GetBaseAttr().player_id  = ret.playerid;
                temp.play.EnterGame(null, true);
                break;
            }

            case GameBase.Network.Internal.Define.ADDROLEDATA_ITEM_RET:
            {
                GameBase.Network.Internal.AddRoleData_Item_Ret ret = new GameBase.Network.Internal.AddRoleData_Item_Ret();
                ret.Create(buff);
                PlayerObject play = UserEngine.Instance().FindPlayerObjectToID(ret.gameid);
                if (play == null)
                {
                    Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:4");
                    break;
                }
                play.GetItemSystem().AwardItem_Ret(ret.sordid, ret.id);
                break;
            }

            case GameBase.Network.Internal.Define.LOADROLEDATA_ITEM:
            {
                GameBase.Network.Internal.ROLEDATA_ITEM item = new GameBase.Network.Internal.ROLEDATA_ITEM();
                item.Create(buff);
                TempPlayObject play = UserEngine.Instance().GetTempPlayObj(item.key, item.key2);
                if (play == null)
                {
                    Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:5");
                    break;
                }
                for (int i = 0; i < item.mListItem.Count; i++)
                {
                    play.play.GetItemSystem().AddItemInfo(item.mListItem[i]);
                }
                break;
            }

            case GameBase.Network.Internal.Define.LOADROLEDATA_MAGIC:
            {
                GameBase.Network.Internal.RoleData_Magic magic = new GameBase.Network.Internal.RoleData_Magic();
                magic.Create(buff);
                TempPlayObject play = UserEngine.Instance().GetTempPlayObj(magic.key, magic.key2);
                if (play == null)
                {
                    Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:6");
                    break;
                }
                for (int i = 0; i < magic.mListMagic.Count; i++)
                {
                    GameBase.Network.Internal.MagicInfo info = magic.mListMagic[i];
                    play.play.GetMagicSystem().AddMagicInfo(info);
                }

                break;
            }

            case GameBase.Network.Internal.Define.KICKGAMEPLAY:
            {
                GameBase.Network.Internal.KickGamePlay kickplay = new GameBase.Network.Internal.KickGamePlay();
                kickplay.Create(buff);
                PlayerObject play = UserEngine.Instance().FindPlayerObjectToAccountId(kickplay.accountid);
                if (play != null)
                {
                    SessionManager.Instance().RemoveSession(play.GetGameSession().m_Socket);
                    play.Kick();
                }
                break;
            }

            case GameBase.Network.Internal.Define.LOADROLEDATA_EUDEMON:
            {
                GameBase.Network.Internal.ROLEDATE_EUDEMON eudemon = new GameBase.Network.Internal.ROLEDATE_EUDEMON();
                eudemon.Create(buff);

                TempPlayObject play = UserEngine.Instance().GetTempPlayObj(eudemon.key, eudemon.key2);
                if (play == null)
                {
                    //只是为了下断点后延迟问题解决方案
                    PlayerObject _play = UserEngine.Instance().FindPlayerObjectToPlayerId(eudemon.playerid);
                    if (_play == null)
                    {
                        Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:6");
                    }
                    else
                    {
                        _play.GetEudemonSystem().DB_Load(eudemon);
                        _play.GetEudemonSystem().SendAllEudemonInfo();
                    }

                    break;
                }
                else
                {
                    play.play.GetEudemonSystem().DB_Load(eudemon);
                }


                break;
            }

            case GameBase.Network.Internal.Define.LOADROLEDATA_FRIEND:
            {
                GameBase.Network.Internal.ROLEDATA_FRIEND friend = new GameBase.Network.Internal.ROLEDATA_FRIEND();
                friend.Create(buff);
                TempPlayObject play = UserEngine.Instance().GetTempPlayObj(friend.key, friend.key2);
                if (play == null)
                {
                    //只是为了下断点后延迟问题解决方案
                    PlayerObject _play = UserEngine.Instance().FindPlayerObjectToPlayerId(friend.playerid);
                    if (_play == null)
                    {
                        Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:7");
                    }
                    else
                    {
                        _play.GetFriendSystem().DB_Load(friend);
                        _play.GetFriendSystem().SendAllFriendInfo();
                    }

                    break;
                }
                else
                {
                    play.play.GetFriendSystem().DB_Load(friend);
                }

                break;
            }

            case GameBase.Network.Internal.Define.GUANJUEDATA:     //爵位数据
            {
                GameBase.Network.Internal.GUANJUEINFO juewei = new GameBase.Network.Internal.GUANJUEINFO();
                juewei.Create(buff);
                GuanJueManager.Instance().DB_Load(juewei);
                break;
            }

            case GameBase.Network.Internal.Define.LOADLEGION:     //军团数据
            {
                GameBase.Network.Internal.LEGIONINFO info = new GameBase.Network.Internal.LEGIONINFO();
                info.Create(buff);
                LegionManager.Instance().DB_Load(info);
                break;
            }

            case GameBase.Network.Internal.Define.CREATELEGION_RET:    //创建军团返回数据
            {
                GameBase.Network.Internal.CreateLegion_Ret info = new GameBase.Network.Internal.CreateLegion_Ret();
                info.Create(buff);
                LegionManager.Instance().CreateLegion_Ret(info);
                break;
            }

            case GameBase.Network.Internal.Define.LOADPAYRECINFO:     //充值数据
            {
                GameBase.Network.Internal.PackPayRecInfo info = new GameBase.Network.Internal.PackPayRecInfo();
                info.Creaet(buff);
                PayManager.Instance().DB_Load(info);
                break;
            }
            }
        }
コード例 #23
0
ファイル: PlayerTrad.cs プロジェクト: tangfengray/soul
        //添加交易道具
        public void AddTradItem(uint itemid)
        {
            PlayerObject     obj     = UserEngine.Instance().FindPlayerObjectToTypeID(GetTradTarget());
            RoleData_Eudemon eudemon = null;

            if (obj == null)
            {
                return;
            }
            GameStruct.RoleItemInfo info = null;
            if (itemid >= IDManager.eudemon_start_id)
            {
                eudemon = play.GetEudemonSystem().FindEudemon(itemid);
                if (eudemon == null)
                {
                    return;
                }
                info = play.GetItemSystem().FindItem(eudemon.itemid);
            }
            else
            {
                info = play.GetItemSystem().FindItem(itemid);
            }

            if (info == null)
            {
                return;
            }
            //最多二十个道具
            if (mListItem.Count >= 20)
            {
                return;
            }
            //对面包裹满了-
            if (info.postion == NetMsg.MsgItemInfo.ITEMPOSITION_BACKPACK)
            {
                if (obj.GetItemSystem().IsItemFull())
                {
                    play.LeftNotice("对方物品栏已满,无法放置更多道具");
                    return;
                }
            }//幻兽栏已满
            else if (info.postion == NetMsg.MsgItemInfo.ITEMPOSITION_EUDEMON_PACK)
            {
                if (obj.GetEudemonSystem().IsEudemonFull())
                {
                    play.LeftNotice("对方幻兽栏已满,无法放置更多道具");
                    return;
                }
            }


            mListItem.Add(info);
            //幻兽数据
            //发给对方道具数据
            obj.GetItemSystem().SendItemInfo(info, NetMsg.MsgItemInfo.TAG_TRADITEM);

            if (info.postion == NetMsg.MsgItemInfo.ITEMPOSITION_EUDEMON_PACK)
            {
                eudemon = play.GetEudemonSystem().FindEudemon(itemid);
                if (eudemon != null)
                {
                    mListEudemon.Add(eudemon);
                    play.GetEudemonSystem().SendLookTradEudemonInfo(obj, eudemon);
                }
            }
        }
コード例 #24
0
        public void Run()
        {
            //每半分钟一个轮循
            if (System.Environment.TickCount - mRunTick > 1000 * 30)
            {
                mRunTick = System.Environment.TickCount;
                for (int i = 0; i < mListInfo.Count; i++)
                {
                    if (DateTime.Now.Year != 0 && DateTime.Now.Year != mListInfo[i].year)
                    {
                        continue;
                    }
                    if (DateTime.Now.Month != 0 && DateTime.Now.Month != mListInfo[i].month)
                    {
                        continue;
                    }
                    if (DateTime.Now.Day != 0 && DateTime.Now.Day != mListInfo[i].day)
                    {
                        continue;
                    }
                    if (DateTime.Now.Hour != mListInfo[i].hour)
                    {
                        continue;
                    }
                    if (DateTime.Now.Minute != mListInfo[i].minute)
                    {
                        continue;
                    }
                    ScripteManager.Instance().ExecuteAction(mListInfo[i].script_id, null);
                    mListInfo[i].bTag = true;
                }
            }


            //三十分钟-
            //恢复已运行的事件标记
            if (System.Environment.TickCount - mClearTagTick > 1000 * 60 * 30)
            {
                mClearTagTick = System.Environment.TickCount;
                for (int i = 0; i < mListInfo.Count; i++)
                {
                    if (DateTime.Now.Hour != mListInfo[i].hour &&
                        mListInfo[i].bTag)
                    {
                        mListInfo[i].bTag = false;
                    }
                }
            }
            //每一秒一个轮询
            if (mPlayTimeOut.ToNextTime() &&
                mListPlayTimeOut.Count > 0)
            {
                int amount = mListPlayTimeOut.Count;
                while (amount > 0)
                {
                    amount--;
                    if (mListPlayTimeOut[amount].TimeOut.IsToNextTime() &&
                        mListPlayTimeOut[amount].IsOnline &&
                        mListPlayTimeOut[amount].callback_scripte_id > 0)
                    {
                        PlayerObject play = UserEngine.Instance().FindPlayerObjectToPlayerId(mListPlayTimeOut[amount].id);
                        if (play == null)
                        {
                            continue;
                        }
                        ScripteManager.Instance().ExecuteAction(mListPlayTimeOut[amount].callback_scripte_id, play);
                        mListPlayTimeOut.RemoveAt(amount);
                    }
                }
            }
        }
コード例 #25
0
 public static void Stop()
 {
     UserEngine.Instance().Stop();
     mTcpServer.Dispose();
     SessionManager.Instance().Dispose();
 }
コード例 #26
0
ファイル: SessionManager.cs プロジェクト: tangfengray/soul
        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;
                    }
                    }
                }
            }
        }