예제 #1
0
        public override void Push2Processor(RPC.RPCSpecialHolder holder, int ptype)
        {
            if (ptype == (int)RPC.PackageType.PKGT_C2P_Player_Send || ptype == (int)RPC.PackageType.PKGT_C2P_Player_SendAndWait)
            {
                Planes.MapInstance mapInstance = Planes.MapInstanceManager.Instance.GetMapInstance(holder.mForward.MapIndexInServer);
                if (mapInstance == null)
                {
                    holder.DestroyBuffer();
                    Log.Log.Server.Info("玩家地图索引非法");
                    return;
                }

                RPC.RPCSpecialHolderProcessor RpcProcessor = mapInstance.RpcProcessor;
                if (RpcProcessor == null)
                {
                    holder.DestroyBuffer();
                    Log.Log.Server.Info("地图的RPC处理器不合法");
                    //RPC.PackageWriter pkg = new RPC.PackageWriter();
                    //H_RPCRoot.smInstance.HGet_GateServer(pkg).DisconnectPlayerByConnectHandle(pkg, holder.mForward.Handle);
                    //pkg.DoCommand(holder.mForward.Planes2GateConnect, RPC.CommandTargetType.DefaultType);
                    return;
                }
                Planes.PlayerInstance player = mapInstance.GetPlayer(holder.mForward.PlayerIndexInMap);
                if (player == null)
                {//切换地图后还有数据包发来该位面
                    holder.DestroyBuffer();

                    //Log.FileLog.WriteLine("找不到RPC处理的玩家");
                    //RPC.PackageWriter pkg = new RPC.PackageWriter();
                    //H_RPCRoot.smInstance.HGet_GateServer(pkg).DisconnectPlayerByConnectHandle(pkg, holder.mForward.Handle);
                    //pkg.DoCommand(holder.mForward.Planes2GateConnect, RPC.CommandTargetType.DefaultType);
                    return;
                }
                else
                {
                    if (player.Id != holder.mForward.RoleId)
                    {
                        holder.DestroyBuffer();
                        Log.FileLog.WriteLine("RPC玩家Id不符合");
                        return;
                    }
                    holder.mRoot = player;
                    //RPC.RPCSpecialHolderProcessor.Process(holder);
                    RpcProcessor.PushHolder(holder);
                    return;
                }
            }

            holder.DestroyBuffer();
            return;
        }
예제 #2
0
        public void ClientDisConnect(ulong roleId, Iocp.NetConnection connect, RPC.RPCForwardInfo fwd)
        {
            //清理干净角色后,返回给DS玩家的PlayerData
            Planes.PlayerInstance player = Planes.PlanesServerDataManager.Instance.FindPlayerInstance(roleId);
            if (player == null)
            {
                Log.Log.Server.Print("ClientDisConnect:找不到角色");
                return;
            }
            Planes.MapInstance    map    = player.HostMap;
            Planes.PlanesInstance planes = player.PlanesInstance;

            if (map != null)
            {
                planes = player.PlanesInstance;
                map.PlayerLeaveMap(player, true);//退出地图,并且存盘
            }
            else
            {
                Log.Log.Server.Print("ClientDisConnect:找不到地图");
                return;
            }

            if (planes != null)
            {
                planes.LeavePlanes(roleId);//退出位面
            }
            else
            {
                Log.Log.Server.Print("ClientDisConnect:位面ID不正确");
                return;
            }

            Planes.PlanesServerDataManager.Instance.RemovePlayerInstance(player);//退出服务器

            //客户端连接断开,需要告诉数据服务器,登出账号
            RPC.PackageWriter pkg0 = new RPC.PackageWriter();
            H_RPCRoot.smInstance.HGet_DataServer(pkg0).HGet_PlayerManager(pkg0).LogoutAccount(pkg0, player.AccountId, (sbyte)eServerType.Planes);
            pkg0.DoCommand(mDataConnect, RPC.CommandTargetType.DefaultType);

            return;
        }
예제 #3
0
        public void ReturnToRoleSelect(ulong planesId, ulong roleId, ulong accountId, Iocp.NetConnection connect, RPC.RPCForwardInfo fwd)
        {//这里的fwd只能用ReturnSerialId
            Planes.PlayerInstance player = Planes.PlanesServerDataManager.Instance.FindPlayerInstance(roleId);
            if (player == null)
            {
                RPC.PackageWriter retPkg = new RPC.PackageWriter();
                retPkg.Write((sbyte)-1);//找不到角色
                retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }
            Planes.MapInstance    map    = player.HostMap;
            Planes.PlanesInstance planes = null;

            if (map != null)
            {
                planes = map.Planes;
                map.PlayerLeaveMap(player, true);//退出地图
            }
            else
            {
                RPC.PackageWriter retPkg = new RPC.PackageWriter();
                retPkg.Write((sbyte)-2);//找不到地图
                retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }

            if (planes != null)
            {
                planes.LeavePlanes(roleId);//退出位面
            }
            else
            {
                RPC.PackageWriter retPkg = new RPC.PackageWriter();
                retPkg.Write((sbyte)-3);//位面ID不正确
                retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }

            Planes.PlanesServerDataManager.Instance.RemovePlayerInstance(player);//退出服务器

            UInt16 SavedReturnSerialId = fwd.ReturnSerialId;

            RPC.PackageWriter pkg = new RPC.PackageWriter();
            H_RPCRoot.smInstance.HGet_DataServer(pkg).HGet_PlayerManager(pkg).LogoutRole(pkg, roleId, player.PlayerData);
            pkg.WaitDoCommand(mDataConnect, RPC.CommandTargetType.DefaultType, new System.Diagnostics.StackTrace(1, true)).OnFarCallFinished = delegate(RPC.PackageProxy _io, bool bTimeOut)
            {
                sbyte successed = -1;
                _io.Read(out successed);

                RPC.PackageWriter retPkg = new RPC.PackageWriter();
                switch (successed)
                {
                case -1:
                    retPkg.Write((sbyte)-2);    //数据服务器LogoutPlayer失败
                    retPkg.DoReturnCommand2(connect, SavedReturnSerialId);
                    break;

                case 1:
                case 2:
                    retPkg.Write((sbyte)1);
                    retPkg.DoReturnCommand2(connect, SavedReturnSerialId);
                    break;

                default:
                    retPkg.Write((sbyte)2);
                    retPkg.DoReturnCommand2(connect, SavedReturnSerialId);
                    break;
                }
            };
        }
예제 #4
0
        //yzb
        void OnDataServerConnected(Iocp.TcpClient pClient, byte[] pData, int nLength)
        {
            if (nLength == 0)
            {
                return;
            }
            if (mLinkState != PlanesServerState.Working)
            {
                if (false == mTcpSrv.Open(Iocp.TcpOption.ForPlanesServer, mParameter.ListenPort))
                {
                    return;
                }
                System.Diagnostics.Debug.WriteLine("DateServer连接成功,PlanesServer开始接受GateServer接入");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("PlanesServer与DataServer断线后重连接成功");
            }
            mLinkState = PlanesServerState.Working;

            //注册到data服务器
            RPC.PackageWriter pkg = new RPC.PackageWriter();
            H_RPCRoot.smInstance.HGet_DataServer(pkg).RegPlanesServer(pkg, mParameter.ListenIP, mParameter.ListenPort, mParameter.ServerId);

            pkg.WaitDoCommand(mDataConnect, RPC.CommandTargetType.DefaultType, null).OnFarCallFinished = delegate(RPC.PackageProxy _io, bool bTimeOut)
            {
                RPC.DataReader dr;
                _io.Read(out dr);

                //读取区服务器信息
                int liCount = 0;
                dr.Read(out liCount);
                for (int i = 0; i < liCount; i++)
                {
                    ushort lAreaId   = 0;
                    string lAreaName = "";
                    dr.Read(out lAreaId);
                    dr.Read(out lAreaName);

                    CSCommon.Data.PlanesData planesData = new CSCommon.Data.PlanesData();
                    planesData.PlanesId   = lAreaId;    //区ID
                    planesData.PlanesName = lAreaName;  //区名
                    Planes.MapInstanceManager.Instance.PlanesManager.GetPlanesInstance(planesData);
                }

                //地图信息
                liCount = 0;
                dr.Read(out liCount);
                for (int i = 0; i < liCount; i++)
                {
                    int liAreaId = 0;
                    dr.Read(out liAreaId);
                    int liMapId = 0;
                    dr.Read(out liMapId);

                    //启动地图
                    Planes.PlanesInstance planes;
                    if (Planes.MapInstanceManager.Instance.PlanesManager.AllPlanesInstance.TryGetValue((ulong)liAreaId, out planes))
                    {
                        Planes.MapInstance map = null;
                        map = planes.GetGlobalMap((ushort)liMapId);
                        if (map == null)
                        {
                            map = Planes.MapInstanceManager.Instance.CreateMapInstance(planes, 0, (ushort)liMapId, null);
                            if (map == null)
                            {
                                map = Planes.MapInstanceManager.Instance.GetDefaultMapInstance(planes);
                            }
                            planes.AddGlobalMap((ushort)liMapId, map);
                        }
                    }
                }
            };

            //同步国战信息
            PlanesCountryWar.CCountryWarMgr.Instance.Start();
        }