Ejemplo n.º 1
0
        public void PlanesServerDisconnected(Iocp.TcpConnect connect)
        {
            List <string> removes = new List <string>();

            foreach (var i in mGlobalMaps)
            {
                if (i.Value.mConnect.Connect == connect)
                {
                    removes.Add(i.Key);
                }
            }
            foreach (var i in removes)
            {
                mGlobalMaps.Remove(i);
            }

            List <ulong> removeIns = new List <ulong>();

            foreach (var i in mInstanceMaps)
            {
                if (i.Value.mConnect.Connect == connect)
                {
                    removeIns.Add(i.Key);
                }
            }
            foreach (var i in removeIns)
            {
                mInstanceMaps.Remove(i);
            }
        }
Ejemplo n.º 2
0
        public void ServerDisConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
        {
            accountList.Clear();
            if (mGateServers.ContainsKey(pConnect))
            {
                mGateServers.Remove(pConnect);
                foreach (var i in this.PlayerManager.AccountDict)
                {
                    if (i.Value.Data2GateConnect == pConnect && (i.Value.CurPlayer == null || i.Value.CurPlayer.mPlanesConnect == null))
                    {
                        accountList.Add(i.Value);
                    }
                }

                foreach (var account in accountList)
                {
                    PlayerManager.ClearAccount(account);
                }
            }

            mPlanesMgr.OnPlanesSeverDisconnect(pConnect);
            mPlanesServers.Remove(pConnect);

            if (null == CloseThread)
            {
                CloseThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadCloses));
                CloseThread.Start();
            }
        }
Ejemplo n.º 3
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                this.treeView1.Nodes.Clear();
                ServerCommon.IGateServer gateServer = ServerModule.Instance.Server;

                TreeNode node = this.treeView1.Nodes.Add("Client");
                //foreach (ServerCommon.Gate.ClientLinker elem in gateServer.ClientLinkers)
                for (int i = 0; i < gateServer.ClientLinkers.Length; i++)
                {
                    var elem = gateServer.ClientLinkers[i];
                    if (elem != null)
                    {
                        var curClientLinker = elem.mForwardInfo.Gate2ClientConnect.m_BindData as ServerCommon.Gate.ClientLinker;
                        if (elem != curClientLinker)
                        {
                            Log.Log.Common.Print("Error!if (gateServer.ClientLinkers[elem.mForwardInfo.Handle] != curClientLinker)");
                            //gateServer.FreeLinker(elem);
                            continue;
                        }

                        Iocp.TcpConnect connect = elem.mForwardInfo.Gate2ClientConnect as Iocp.TcpConnect;
                        node.Nodes.Add(connect.IpAddress + ":" + connect.Port).Tag = elem;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Log.Log.Common.Print(ex.ToString());
            }
        }
Ejemplo n.º 4
0
        public void ServerDisConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
        {
            lock (this)
            {
                mAllConnect.Remove(pConnect);
                if (mDataServer != null && pConnect == mDataServer.Connect)
                {
                    mDataServer = null;
                }
                if (mLogServer != null && pConnect == mLogServer.Connect)
                {
                    mLogServer = null;
                }
                if (mComServer != null && pConnect == mComServer.Connect)
                {
                    mComServer = null;
                }
                mGateServers.Remove(pConnect);
                mPlanesServers.Remove(pConnect);
                PathFindServers.Remove(pConnect);

                ServerInfo si = pConnect.m_BindData as ServerInfo;
                Log.Log.Server.Print("有服务器{0}断开连接,分配端口{1}", si.Id, si.Port);

                FreeServerPort(si);
            }
        }
Ejemplo n.º 5
0
        public UInt16 RegPlanesServer(ulong id, Iocp.NetConnection connect)
        {
            if (id == 0)
            {
                Log.Log.Server.Print("RegPlanesServer id is Empty");
            }

            ServerInfo si = connect.m_BindData as ServerInfo;

            si.Id = id;
            Iocp.TcpConnect tcpConnect = connect as Iocp.TcpConnect;
            si.Ip                   = tcpConnect.IpAddress;
            si.LinkNumber           = 0;
            mPlanesServers[connect] = si;

            Log.Log.Server.Print("Planes服务器{0}注册,{1}:{2}", si.Id, si.Ip, si.Port);

            foreach (var i in mGateServers)
            {
                //i.Value.Connect
                RPC.PackageWriter pkg = new RPC.PackageWriter();
                H_RPCRoot.smInstance.HGet_GateServer(pkg).NewPlanesServerStarted(pkg);
                pkg.DoCommand(i.Value.Connect, RPC.CommandTargetType.DefaultType);
            }
            return(si.Port);
        }
Ejemplo n.º 6
0
        public void ClientConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
        {
            lock (mAllClientShortConnect)
            {
                if (pServer == this.mClientLoginSrv)
                {
                    pConnect.mLimitLevel = (int)RPC.RPCExecuteLimitLevel.Player;
                    foreach (Iocp.TcpConnect conn in mAllClientShortConnect)
                    {
                        if (conn == pConnect)
                        {
                            return;
                        }
                    }
                    var linkedInfo = new ClientLinkedInfo();
                    pConnect.m_BindData = linkedInfo;

                    mAllClientShortConnect.Add(pConnect);
                }
                else
                {
                    pConnect.Disconnect();
                }
            }
        }
Ejemplo n.º 7
0
        public void QueryGlobalMapPath(Iocp.TcpConnect connect, UInt16 serialId, ulong planesId, ulong mapSourceId, ulong roleId, SlimDX.Vector3 from, SlimDX.Vector3 to, bool bClear)
        {
            PFPlanes planes;

            if (PlanesDic.TryGetValue(planesId, out planes) == false)
            {
                planes          = new PFPlanes();
                planes.PlanesId = planesId;
                PlanesDic.Add(planesId, planes);

                var thread = SelectPFThread();
                thread.PushPlanes(planes);
            }

            PFMap map = planes.GetMap(mapSourceId);

            PFUnit unit = map.GetUnit(roleId);

            PFQuery query = new PFQuery();

            query.FromPt   = from;
            query.ToPt     = to;
            query.Connect  = connect;
            query.SerialId = serialId;
            unit.AddQuery(query, bClear);
        }
Ejemplo n.º 8
0
 public void ServerConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
 {
     lock (this)
     {
         if (pServer == this.mTcpSrv)
         {
             ServerInfo si = AllocServerPort(pConnect.IpAddress, pConnect);
             pConnect.mLimitLevel = this.mTcpSrv.LimitLevel;
             pConnect.m_BindData  = si;
             Log.Log.Server.Print("有服务器{0}接入,分配端口{1}", si.Id, si.Port);
             foreach (Iocp.TcpConnect conn in mAllConnect)
             {
                 if (conn == pConnect)
                 {
                     return;
                 }
             }
             mAllConnect.Add(pConnect);
         }
         else
         {
             pConnect.Disconnect();
         }
     }
 }
Ejemplo n.º 9
0
 public void ClientDisConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
 {
     lock (mAllClientShortConnect)
     {
         pConnect.m_BindData = null;
         mAllClientShortConnect.Remove(pConnect);
     }
 }
Ejemplo n.º 10
0
 public SByte RegLogServer(string ListenIp, UInt16 ListenPort, ulong id, Iocp.NetConnection connect)
 {
     if (mLogServer != null)
     {
         Iocp.TcpConnect conn = mLogServer.Connect as Iocp.TcpConnect;
         if (conn != null)
         {//Log服务器是唯一的,起来一个就要把另外一个踢下线
             conn.Disconnect();
         }
     }
     mLogServer         = new ServerFrame.NetEndPoint(ListenIp, ListenPort);
     mLogServer.Connect = connect;
     mLogServer.Id      = id;
     return(1);
 }
Ejemplo n.º 11
0
        private bool InitRoleInstance(PlanesInstance planes, CSCommon.Data.PlayerData pd, Iocp.TcpConnect p2gConnect, UInt16 linkId)
        {
            mPlanes2GateConnect = p2gConnect;
            mClientLinkId       = linkId;

            mPlayerData = pd;
            mPlayerData.RoleDetail._SetHostPlayer(this);
            Bag.InventoryType = CSCommon.eItemInventory.ItemBag;

            //var sp = CSCommon.RoleCommonData.Instance.SexProToTId.Find(x => ((byte)x.Sex == pd.RoleDetail.Sex && (byte)x.Pro == pd.RoleDetail.Profession));
            //if (sp == null)
            //{
            //    Log.Log.Common.Print("SexProToTId is Null sex={0},pro={1}", pd.RoleDetail.Sex, pd.RoleDetail.Profession);
            //    return false;
            //}

            mPlayerData.RoleDetail.TemplateId = CSCommon.CommonUtil.GetTemplateIDBySexAndPro(pd.RoleDetail.Sex, pd.RoleDetail.Profession);

            #region 背包初始化
            Bag.InitBag(this, mPlayerData.RoleDetail.BagSize, mPlayerData.BagItems);
            EquipBag.InitBag(this, (UInt16)CSCommon.eEquipType.MaxBagSize, mPlayerData.EquipedItems);
            FashionBag.InitBag(this, byte.MaxValue, mPlayerData.FashionItems);
            EquipGemBag.InitBag(this, (UInt16)CSCommon.eEquipType.MaxBagSize, mPlayerData.EquipGemItems);
            GemBag.InitBag(this, (UInt16)CSCommon.eEquipType.MaxBagSize, mPlayerData.GemItems);
            #endregion
            InitMartial();
            #region 任务初始化
            InitTask(mPlayerData.TaskData);
            mRecordMgr.Init(this, mPlayerData.AchieveData);
            #endregion
            mSkillMgr.InitBag(this, mPlayerData.SkillDatas);
            #region 状态机初始化
            InitState();
            #endregion
            CalcAllValues();

            //mPlayerData.RoleDetail.RoleMaxHp = FinalRoleValue.MaxHP;
            //暂时先这样,以后需要客户端操作复活
            //if (CurHP <= 0)
            //    Relive();

            //EventDispacth.Instance.AddListener(eGlobleEvent.Fight_KillActor, this);



            return(true);
        }
Ejemplo n.º 12
0
        public SByte RegDataServer(string ListenIp, UInt16 ListenPort, ulong id, Iocp.NetConnection connect)
        {
            if (mDataServer != null)
            {
                Iocp.TcpConnect conn = mDataServer.Connect as Iocp.TcpConnect;
                if (conn != null)
                {//数据服务器是唯一的,起来一个就要把另外一个踢下线
                    conn.Disconnect();
                }
            }
            mDataServer         = new ServerFrame.NetEndPoint(ListenIp, ListenPort);
            mDataServer.Connect = connect;
            mDataServer.Id      = id;

            Log.Log.Server.Print("Data服务器{0}注册,{1}:{2}", id, ListenIp, ListenPort);
            return(1);
        }
Ejemplo n.º 13
0
        public static PlayerInstance CreatePlayerInstance(CSCommon.Data.PlayerData pd, Iocp.TcpConnect p2gConnect, UInt16 linkId)
        {
            IActorInitBase actInit = new IActorInitBase();

            actInit.GameType = eActorGameType.Player;
            PlayerInstance ret = new PlayerInstance();

            ret.Initialize(actInit);
            if (false == ret.InitRoleInstance(null, pd, p2gConnect, linkId))
            {
                return(null);
            }

            return(ret);
        }
Ejemplo n.º 14
0
        protected void ReceiveData(Iocp.NetConnection sender, byte[] pData, int nLength)
        {
            var pkg = new PackageProxy(pData, nLength);

            System.UInt16 serialId = pkg.SerialId;

            RPCForwardInfo fwd = null;

            if (mGateServerForward != null)
            {
                fwd = mGateServerForward.GetForwardInfo(sender);
            }

            Iocp.TcpConnect tcpConnect = sender as Iocp.TcpConnect;

            int LimitLevel = (int)RPCExecuteLimitLevel.Developer;

            if (tcpConnect != null)
            {
                LimitLevel = tcpConnect.mLimitLevel;
            }

            //只有对外的GateServer才需要判断权限,更新最高权限
            if (fwd != null)
            {
                LimitLevel = fwd.LimitLevel;
            }

            if (fwd != null && (PackageType)pkg.PkgType >= PackageType.PKGT_C2P_Send)
            {
                switch ((PackageType)pkg.PkgType)
                {
                case PackageType.PKGT_C2P_Send:
                case PackageType.PKGT_C2P_Player_Send:
                {
                    Iocp.NetConnection conn = fwd.Gate2PlanesConnect;
                    if (conn != null)
                    {
                        var fwdPkg = new PackageWriter(pData, nLength);
                        fwd.Write(fwdPkg);
                        fwdPkg.SendBuffer(conn);
                    }
                }
                    return;

                case PackageType.PKGT_C2P_SendAndWait:
                case PackageType.PKGT_C2P_Player_SendAndWait:
                {
                    Iocp.NetConnection conn = fwd.Gate2PlanesConnect;
                    if (conn != null)
                    {
                        var fwdPkg = new PackageWriter(pData, nLength);
                        fwd.Write(fwdPkg);
                        fwdPkg.SendBuffer(conn);
                    }
                }
                    return;

                case PackageType.PKGT_C2P_Return:
                {
                    if (mGateServerForward == null)
                    {
                        Log.Log.Common.Print("肯定有人改分包了,不是Gate但是收到PKGT_C2P_Return");
                    }
                    System.UInt16 handle;
                    //pkg.SeekTo(nLength-sizeof(RPCHeader)-sizeof(System.UInt16));
                    pkg.SeekTo(nLength - PackageProxy.HeaderSize - sizeof(System.UInt16));
                    pkg.Read(out handle);
                    pkg.SeekTo(0);
                    Iocp.NetConnection conn = mGateServerForward.GetConnectByHandle(handle);
                    if (conn != null)
                    {
                        var fwdPkg = new PackageWriter(pData, nLength - sizeof(System.UInt16));
                        fwdPkg.PkgType = PackageType.PKGT_Return;
                        fwdPkg.SendBuffer(conn);
                    }
                }
                    return;
                }
            }

            if (fwd == null)
            {
                fwd = new RPCForwardInfo();
                fwd.ReturnSerialId     = serialId;
                fwd.Gate2ClientConnect = sender;
                fwd.Planes2GateConnect = sender;
            }
            else
            {
                fwd.ReturnSerialId = serialId;
            }

            switch ((PackageType)pkg.PkgType)
            {
            case PackageType.PKGT_Send:
            {        //远端直接执行
                RPCEntrance.Execute(LimitLevel, sender, mRootObject, pkg, fwd);
            }
            break;

            case PackageType.PKGT_SendAndWait:
            {        //远端执行后,返回执行结束
                System.Object retObject = RPCEntrance.Execute(LimitLevel, sender, mRootObject, pkg, fwd);
                if (retObject == null || retObject.GetType() == typeof(void))
                {
                    break;
                }
                var retPkg = new PackageWriter();
                retPkg.SerialId = serialId;
                retPkg.WritePODObject(retObject);
                retPkg.DoReturnCommand(sender, CommandTargetType.DefaultType);
            }
            break;

            case PackageType.PKGT_C2P_Send:
            {
                //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize());
                pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize());
                fwd.Read(pkg);
                pkg.SeekTo(0);
                System.Object retObject = RPCEntrance.Execute(fwd.LimitLevel, fwd.Planes2GateConnect, mRootObject, pkg, fwd);
            }
            break;

            case PackageType.PKGT_C2P_Player_Send:
            {
                if (mPlanesServerSpecialRoot == null)
                {
                    Log.Log.Common.Print("有人改分包了,不是Planes但是收到PKGT_C2P_Player_Send消息");
                    break;
                }

                RPCSpecialHolder holder = new RPCSpecialHolder(pData, nLength - RPCForwardInfo.GetBlockSize());
                holder.mForward = new RPCForwardInfo();

                //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize());
                pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize());
                holder.mForward.Read(pkg);
                pkg.SeekTo(0);
                holder.mForward.ReturnSerialId     = serialId;
                holder.mForward.Planes2GateConnect = sender;

                mPlanesServerSpecialRoot.Push2Processor(holder, (int)PackageType.PKGT_C2P_Player_Send);
            }
            break;

            case PackageType.PKGT_C2P_SendAndWait:
            {
                //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize());
                pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize());
                fwd.Read(pkg);
                pkg.SeekTo(0);
                System.Object retObject = RPCEntrance.Execute(fwd.LimitLevel, fwd.Planes2GateConnect, mRootObject, pkg, fwd);
                if (retObject == null || retObject.GetType() == typeof(void))
                {
                    //Log.Log.Common.Print("有人改分包了,不是Planes但是收到PKGT_C2P_SendAndWait消息");
                    break;
                }
                var retPkg = new PackageWriter();
                retPkg.SerialId = serialId;
                retPkg.WritePODObject(retObject);
                retPkg.Write(fwd.Handle);
                retPkg.DoReturnCommand(sender, CommandTargetType.Planes);
            }
            break;

            case PackageType.PKGT_C2P_Player_SendAndWait:
            {
                if (mPlanesServerSpecialRoot == null)
                {
                    Log.Log.Common.Print("有人改分包了,不是Planes但是收到PKGT_C2P_Player_SendAndWait消息");
                    break;
                }
                var holder = new RPCSpecialHolder(pData, nLength - RPCForwardInfo.GetBlockSize());
                holder.mForward = new RPCForwardInfo();
                holder.mForward.ReturnSerialId = serialId;
                //pkg.SeekTo(nLength-sizeof(RPCHeader)-RPCForwardInfo.GetBlockSize());
                pkg.SeekTo(nLength - PackageProxy.HeaderSize - RPCForwardInfo.GetBlockSize());
                holder.mForward.Read(pkg);
                pkg.SeekTo(0);
                holder.mForward.Planes2GateConnect = sender;

                mPlanesServerSpecialRoot.Push2Processor(holder, (int)PackageType.PKGT_C2P_Player_SendAndWait);
            }
            break;

            case PackageType.PKGT_Return:
            {
                OnFarCallFinished(serialId, pkg, false);
            }
            break;

            case PackageType.PKGT_C2P_Return:
            {
                if (mGateServerForward == null)
                {
                    Log.Log.Common.Print("有人改分包了,不是Gate但是收到PKGT_C2P_Return消息");
                    return;
                }
                System.UInt16 handle;
                //pkg.SeekTo(nLength-sizeof(RPCHeader)-sizeof(System.UInt16));
                pkg.SeekTo(nLength - PackageProxy.HeaderSize - sizeof(System.UInt16));
                pkg.Read(out handle);
                pkg.SeekTo(0);
                Iocp.NetConnection conn = mGateServerForward.GetConnectByHandle(handle);
                if (conn != null)
                {
                    var fwdPkg = new PackageWriter(pData, nLength - sizeof(System.UInt16));
                    fwdPkg.PkgType = PackageType.PKGT_Return;
                    fwdPkg.SendBuffer(conn);
                }
            }
            break;

            case PackageType.PKGT_P2C_Send:
            {
                if (mGateServerForward == null)
                {
                    Log.Log.Common.Print("有人改分包了,不是Gate但是收到PKGT_C2P_Return消息");
                    return;
                }
                System.UInt16 handle;
                //pkg.SeekTo(nLength-sizeof(RPCHeader)-sizeof(System.UInt16));
                pkg.SeekTo(nLength - PackageProxy.HeaderSize - sizeof(System.UInt16));
                pkg.Read(out handle);
                pkg.SeekTo(0);
                Iocp.TcpConnect conn = mGateServerForward.GetConnectByHandle(handle) as Iocp.TcpConnect;
                if (conn != null)
                {
                    if (conn.State != Iocp.NetState.Connect)
                    {
                        if (OnP2CCall_WhenClientDisConnect != null)
                        {
                            OnP2CCall_WhenClientDisConnect(handle, conn);
                        }
                    }
                    else
                    {
                        pkg.PkgType = PackageType.PKGT_Send;
                        //pkg.DangrouseSetPkgLength(nLength - sizeof(System.UInt16));

                        conn.SendBuffer(pkg.Ptr, 0, (int)(nLength - sizeof(System.UInt16)));
                    }
                }
            }
                return;
            }
        }
Ejemplo n.º 15
0
 void GateServerDisConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
 {
     mGateServers.Remove(pConnect);
 }
Ejemplo n.º 16
0
 public void OnPlanesSeverDisconnect(Iocp.TcpConnect connect)
 {
     //AllMapManager.Instance.Clear();
     AllMapManager.Instance.PlanesServerDisconnected(connect);
 }
Ejemplo n.º 17
0
 public void ServerDisConnected(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
 {
 }
Ejemplo n.º 18
0
 public void ServerReceiveData(Iocp.TcpConnect pConnect, Iocp.TcpServer pServer, byte[] pData, int nLength)
 {
     ReceiveData(pConnect, pData, nLength);
 }