public void EnterMap(RPC.PackageWriter pkg, CSCommon.Data.PlayerData pd, CSCommon.Data.PlanesData planesData, System.UInt16 mapSourceId, System.UInt64 instanceId, SlimDX.Vector3 pos, System.UInt16 cltHandle) { pkg.Write(pd); pkg.Write(planesData); pkg.Write(mapSourceId); pkg.Write(instanceId); pkg.Write(pos); pkg.Write(cltHandle); pkg.SetMethod(11); }
public MapInstance GetGlobalMap(CSCommon.Data.PlanesData planesData, System.Guid mapSourceId) { PlanesMapManager pmm; if (false == mPlanesMapManagers.TryGetValue(planesData.PlanesId, out pmm)) { pmm = new PlanesMapManager(); pmm.InitPlanes(planesData); mPlanesMapManagers.Add(planesData.PlanesId, pmm); } return(pmm.GetGlobalMap(mapSourceId)); }
public PlanesInstance(CSCommon.Data.PlanesData planesData) { mPlanesData = planesData; if (mPlanesData.PlanesId >= 2048) { Log.Log.Server.Error("位面ID不能超过2048!!!!!!!!!!!,不然创建唯一id可能会有重复!!!"); } if (mPlanesData.PlanesId != 0) {//为0的位面是临时副本逻辑位面,不是真正的服务器 ServerFrame.Util.InitServerID(mPlanesData.PlanesId); } }
//如果PlanesId为Guid.Empty那么说明角色在副本,不在真正的位面内 public PlanesInstance GetPlanesInstance(CSCommon.Data.PlanesData planesData) { PlanesInstance planes; if (AllPlanesInstance.TryGetValue(planesData.PlanesId, out planes)) { return(planes); } planes = new PlanesInstance(planesData); AllPlanesInstance.Add(planesData.PlanesId, planes); return(planes); }
// public void CreatePlanesData(byte level,string name,byte state) // { // CSCommon.Data.PlanesData pd = new CSCommon.Data.PlanesData(); // pd.PlanesId = ServerFrame.Util.GenerateObjID(ServerFrame.GameObjectType.Server); // pd.PlanesName = name; // pd.CreateTime = System.DateTime.Now; // pd.ActiveState = state; // // mPlanes.Add(pd.PlanesId, pd); // // string condition = "PlanesName=\'" + name + "\'"; // ServerFrame.DB.DBOperator dbOp = ServerFrame.DB.DBConnect.ReplaceData(condition, pd, true); // mDataServer.DBLoaderConnect._ExecuteInsert(dbOp); // } CSCommon.Data.PlanesData LoadPlanesFromDB(string planesName) { string condition = "ActiveState>0 && PlanesName = \'" + planesName + "\'"; ServerFrame.DB.DBOperator dbOp = ServerFrame.DB.DBConnect.SelectData(condition, new CSCommon.Data.PlanesData(), ""); System.Data.DataTable tab = mDataServer.DBLoaderConnect._ExecuteSelect(dbOp, "CSCommon.Data.PlanesData"); if (tab == null || tab.Rows.Count != 1) { return(null); } CSCommon.Data.PlanesData pd = new CSCommon.Data.PlanesData(); if (false == ServerFrame.DB.DBConnect.FillObject(pd, tab.Rows[0])) { return(pd); } return(null); }
public PlanesMgr(IDataServer server) { mDataServer = server; //加载所有活跃位面 string condition = "ActiveState>0"; ServerFrame.DB.DBOperator dbOp = ServerFrame.DB.DBConnect.SelectData(condition, new CSCommon.Data.PlanesData(), ""); System.Data.DataTable tab = mDataServer.DBLoaderConnect._ExecuteSelect(dbOp, "CSCommon.Data.PlanesData"); if (tab == null) { return; } foreach (System.Data.DataRow r in tab.Rows) { CSCommon.Data.PlanesData pd = new CSCommon.Data.PlanesData(); if (false == ServerFrame.DB.DBConnect.FillObject(pd, r)) { continue; } mPlanes.Add(pd.PlanesId, pd); } }
public void OtherPlane_EnterMap(RPC.PackageWriter pkg, System.UInt64 planesSeverId, System.UInt16 cltHandle, CSCommon.Data.PlayerData pd, CSCommon.Data.PlanesData planesData, System.UInt16 mapSourceId, System.UInt64 mapInstanceId, SlimDX.Vector3 pos) { pkg.Write(planesSeverId); pkg.Write(cltHandle); pkg.Write(pd); pkg.Write(planesData); pkg.Write(mapSourceId); pkg.Write(mapInstanceId); pkg.Write(pos); pkg.SetMethod(7); }
public void JumpToMap(ushort mapSourceId, float posX, float posY, float posZ, RPC.RPCForwardInfo fwd) { if (mapSourceId == this.HostMap.MapSourceId) { // var retPkg = new RPC.PackageWriter(); // retPkg.Write((sbyte)eRet_GotoMap.SameMap); // retPkg.DoReturnPlanes2Client(fwd); return; } ushort targetPlanesId = this.PlayerData.RoleDetail.PlanesId; if (AllMapManager.IsInstanceMap(mapSourceId)) { targetPlanesId = 0; } SlimDX.Vector3 pos = new SlimDX.Vector3(posX, posY, posZ); var pkg = new RPC.PackageWriter(); H_RPCRoot.smInstance.HGet_DataServer(pkg).GotoMap(pkg, Id, targetPlanesId, mapSourceId, pos, fwd.Handle); pkg.WaitDoCommand(IPlanesServer.Instance.DataConnect, RPC.CommandTargetType.DefaultType, null).OnFarCallFinished = delegate(RPC.PackageProxy _io, bool bTimeOut) { sbyte successed = -1; _io.Read(out successed); switch ((eRet_GotoMap)successed) { case eRet_GotoMap.FailedEnterMap: case eRet_GotoMap.NoConnectInfo: case eRet_GotoMap.NoPlayerData: { _JumpMapDoReturnClient(fwd, successed); return; } break; case eRet_GotoMap.SamePlane: { Planes.MapInstanceManager.Instance.PlayerLeaveMap(this, false); //离开地图 if (this.PlanesInstance != null) { this.PlanesInstance.LeavePlanes(this.Id); //离开位面 } CSCommon.Data.PlanesData planesData = new CSCommon.Data.PlanesData(); _io.Read(planesData); ulong mapInstanceId; _io.Read(out mapInstanceId); var planesInstance = Planes.MapInstanceManager.Instance.PlanesManager.GetPlanesInstance(planesData); planesInstance.EnterPlanes(this); //进位面 Planes.MapInstanceManager.Instance.PlayerEnterMap(this, mapSourceId, mapInstanceId, pos, true); //进地图 var retPkg = new RPC.PackageWriter(); Wuxia.H_RpcRoot.smInstance.RPC_OnJumpMapOver(retPkg, (int)mapSourceId, pos.X, pos.Z); retPkg.DoCommandPlanes2Client(this.Planes2GateConnect, this.ClientLinkId); } break; case eRet_GotoMap.OtherPlane: { Planes.MapInstance map = HostMap; Planes.PlanesInstance planes = PlanesInstance; if (map == null || planes == null) { _JumpMapDoReturnClient(fwd, (sbyte)(eRet_GotoMap.NullMapOrNoPlane)); return; } else { map.PlayerLeaveMap(this, true); //退出地图,这里已经存盘过了 planes.LeavePlanes(Id); //退出位面 Planes.PlanesServerDataManager.Instance.RemovePlayerInstance(this); //退出服务器 var retPkg = new RPC.PackageWriter(); retPkg.Write("跳转成功2"); retPkg.DoReturnPlanes2Client(fwd); return; } } } }; }
public void EnterMap(CSCommon.Data.PlayerData pd, CSCommon.Data.PlanesData planesData, ushort mapSourceId, ulong instanceId, SlimDX.Vector3 pos, UInt16 cltHandle, Iocp.NetConnection connect, RPC.RPCForwardInfo fwd) { // var map = Planes.PlanesManager.Instance.GetGlobalMap(planesData, pd.RoleDetail.MapSourceId); // if (map == null) // return; Planes.PlayerInstance player = Planes.PlanesServerDataManager.Instance.FindPlayerInstance(pd.RoleDetail.RoleId); if (player != null) { //玩家就在这个服务器 Planes.MapInstanceManager.Instance.PlayerLeaveMap(player, false); //离开地图 player.PlanesInstance.LeavePlanes(player.Id); //离开位面 var planes = Planes.MapInstanceManager.Instance.PlanesManager.GetPlanesInstance(planesData); planes.EnterPlanes(player); //进位面 Planes.MapInstanceManager.Instance.PlayerEnterMap(player, mapSourceId, instanceId, pos, true); //进地图 } else { #region CreatePlayerInstance try { player = Planes.PlayerInstance.CreatePlayerInstance(pd, connect as Iocp.TcpConnect, cltHandle); if (player == null)//创建角色 { RPC.PackageWriter pkg = new RPC.PackageWriter(); H_RPCRoot.smInstance.HGet_GateServer(pkg).DisconnectPlayer(pkg, pd.RoleDetail.AccountId, (sbyte)eServerType.Planes); pkg.DoCommand(connect, RPC.CommandTargetType.DefaultType); RPC.PackageWriter retPkg = new RPC.PackageWriter(); retPkg.Write((sbyte)eRet_GotoMap.CreatePlayerFailed); retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId); Log.Log.Server.Print("DataServer1 force disconnect player!"); Log.Log.Server.Print(new System.Diagnostics.StackTrace(0, true).ToString()); return; } } catch (System.Exception ex) { Log.Log.Server.Print(ex.ToString()); Log.Log.Server.Print(ex.StackTrace.ToString()); RPC.PackageWriter pkg = new RPC.PackageWriter(); H_RPCRoot.smInstance.HGet_GateServer(pkg).DisconnectPlayer(pkg, pd.RoleDetail.AccountId, (sbyte)eServerType.Planes); pkg.DoCommand(connect, RPC.CommandTargetType.DefaultType); RPC.PackageWriter retPkg = new RPC.PackageWriter(); retPkg.Write((sbyte)eRet_GotoMap.CreatePlayerFailed); retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId); Log.Log.Server.Print("PlanesServer2 force disconnect player!"); Log.Log.Server.Print(new System.Diagnostics.StackTrace(0, true).ToString()); return; } #endregion Planes.PlanesServerDataManager.Instance.AddPlayerInstance(player); //进服务器 var planes = Planes.MapInstanceManager.Instance.PlanesManager.GetPlanesInstance(planesData); planes.EnterPlanes(player); //进位面 Planes.MapInstanceManager.Instance.PlayerEnterMap(player, mapSourceId, instanceId, pos, true); //进地图 var overPkg = new RPC.PackageWriter(); Wuxia.H_RpcRoot.smInstance.RPC_OnJumpMapOver(overPkg, (int)mapSourceId, pos.X, pos.Z); overPkg.DoCommandPlanes2Client(player.Planes2GateConnect, player.ClientLinkId); } { RPC.PackageWriter retPkg = new RPC.PackageWriter(); retPkg.Write((sbyte)eRet_GotoMap.EnterMap); retPkg.Write(pd.RoleDetail.LocationX); retPkg.Write(pd.RoleDetail.LocationY); retPkg.Write(pd.RoleDetail.LocationZ); //retPkg.Write(player.Id); retPkg.Write(player.PlayerData.RoleDetail.RoleHp); retPkg.Write(player.PlayerData.RoleDetail.RoleMaxHp); retPkg.Write(player.PlayerData.RoleDetail.RoleSpeed); retPkg.Write(player.IndexInMap); retPkg.Write(player.HostMap.IndexInServer); retPkg.DoReturnCommand2(connect, fwd.ReturnSerialId); } return; }
//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(); }
public void InitPlanes(CSCommon.Data.PlanesData planesData) { mPlanesInstance = MapManager.Instance.CreatePlanes(); mPlanesInstance.InitPlanesInstance(planesData); }