private void Release() { m_RoomMgr.StopRoomThread(); CenterClientApi.Release(); IOManager.Instance.Release(); LogSys.Release(); }
internal static void Init() { StringBuilder sb = new StringBuilder(256); if (CenterClientApi.GetConfig("Debug", sb, 256)) { string debug = sb.ToString(); s_Instance.m_Debug = (int.Parse(debug) != 0 ? true : false); if (s_Instance.m_Debug) { GameFramework.GlobalVariables.Instance.IsDebug = true; } } if (CenterClientApi.GetConfig("worldid", sb, 256)) { string worldid = sb.ToString(); int val = int.Parse(worldid); if (s_Instance.m_WorldId != val) { s_Instance.m_WorldId = val; } } }
private void OnCommand(int src, int dest, string command) { const string c_QuitLobby = "QuitLobby"; const string c_ReloadConfig = "ReloadConfig"; try { if (0 == command.CompareTo(c_QuitLobby)) { LogSys.Log(LOG_TYPE.MONITOR, "receive {0} command, save data and then quitting ...", command); if (!m_WaitQuit) { m_UserProcessScheduler.DispatchAction(m_UserProcessScheduler.DoCloseServers); m_LastWaitQuitTime = TimeUtility.GetLocalMilliseconds(); m_WaitQuit = true; } } else if (0 == command.CompareTo(c_ReloadConfig)) { CenterClientApi.ReloadConfigScript(); LobbyConfig.Init(); LogSys.Log(LOG_TYPE.WARN, "receive {0} command.", command); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
internal static void Init() { StringBuilder sb = new StringBuilder(256); if (CenterClientApi.GetConfig("Server", sb, 256)) { s_Instance.m_Server = sb.ToString(); } if (CenterClientApi.GetConfig("User", sb, 256)) { s_Instance.m_User = sb.ToString(); } if (CenterClientApi.GetConfig("Password", sb, 256)) { s_Instance.m_Password = sb.ToString(); } if (CenterClientApi.GetConfig("Database", sb, 256)) { s_Instance.m_Database = sb.ToString(); } if (CenterClientApi.GetConfig("PersistentInterval", sb, 256)) { s_Instance.m_PersistentInterval = uint.Parse(sb.ToString()); } if (CenterClientApi.GetConfig("LoadThreadNum", sb, 256)) { s_Instance.m_LoadThreadNum = int.Parse(sb.ToString()); } if (CenterClientApi.GetConfig("SaveThreadNum", sb, 256)) { s_Instance.m_SaveThreadNum = int.Parse(sb.ToString()); } }
public bool Send(string dest_name, object msg) { bool ret = false; if (null != dest_name) { if (world_id_ == 0) { int handle = CenterClientApi.TargetHandle(dest_name); if (handle != 0) { ret = Send(handle, msg); } } else { int handle = CenterHubApi.TargetHandle(world_id_, dest_name); if (handle != 0) { ret = Send(handle, msg); } } } return(ret); }
private void OnCommand(int src, int dest, string command) { const string c_QuitDataStore = "QuitDataStore"; const string c_ReloadConfig = "ReloadConfig"; try { if (0 == command.CompareTo(c_QuitDataStore)) { LogSys.Log(LOG_TYPE.MONITOR, "receive {0} command, save data and then quitting ...", command); if (!m_WaitQuit) { DataCacheSystem.Instance.QueueAction(DataCacheSystem.Instance.DoLastSave); m_WaitQuit = true; } } else if (0 == command.CompareTo(c_ReloadConfig)) { CenterClientApi.ReloadConfigScript(); DataCacheConfig.Init(); LogSys.Log(LOG_TYPE.WARN, "receive {0} command.", command); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
public bool Send(int dest_handle, object msg) { byte[] data; bool ret = Build(msg, out data); if (ret) { if (null != data) { if (world_id_ == 0) { ret = CenterClientApi.SendByHandle(dest_handle, data, data.Length); } else { ret = CenterHubApi.SendByHandle(world_id_, dest_handle, data, data.Length); } } else { ret = false; } } return(ret); }
private void Init(string[] args) { m_NameHandleCallback = this.OnNameHandleChanged; m_MsgCallback = this.OnMessage; m_MsgResultCallback = this.OnMessageResultCallback; m_CmdCallback = this.OnCommand; m_LogHandler = this.OnCenterLog; CenterClientApi.SetCenterLogHandler(m_LogHandler); CenterClientApi.Init("datacache", args.Length, args, m_NameHandleCallback, m_MsgCallback, m_MsgResultCallback, m_CmdCallback); m_Channel = new PBChannel(DataMessageEnum2Type.Query, DataMessageEnum2Type.Query); m_Channel.DefaultServiceName = "UserSvr"; LogSys.Init("./config/logconfig.xml"); DataCacheConfig.Init(); GlobalVariables.Instance.IsClient = false; string key = "防君子不防小人"; byte[] xor = Encoding.UTF8.GetBytes(key); ResourceReadProxy.OnReadAsArray = ((string filePath) => { byte[] buffer = null; try { buffer = File.ReadAllBytes(filePath); } catch (Exception e) { LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", e.Message, e.StackTrace); return(null); } return(buffer); }); LogSystem.OnOutput += (Log_Type type, string msg) => { switch (type) { case Log_Type.LT_Debug: LogSys.Log(LOG_TYPE.DEBUG, msg); break; case Log_Type.LT_Info: LogSys.Log(LOG_TYPE.INFO, msg); break; case Log_Type.LT_Warn: LogSys.Log(LOG_TYPE.WARN, msg); break; case Log_Type.LT_Error: case Log_Type.LT_Assert: LogSys.Log(LOG_TYPE.ERROR, msg); break; } }; DbThreadManager.Instance.Init(DataCacheConfig.LoadThreadNum, DataCacheConfig.SaveThreadNum); DataOpSystem.Instance.Init(m_Channel); DataCacheSystem.Instance.Init(); LogSys.Log(LOG_TYPE.INFO, "DataCache initialized"); }
private int GetMyHandle() { if (0 == m_MyHandle) { m_MyHandle = CenterClientApi.TargetHandle("Lobby"); } return(m_MyHandle); }
internal static void SendDcoreMessage(string name, JsonMessage msg) { if (s_Inited) { byte[] data = BuildCoreMessage(msg); CenterClientApi.SendByName(name, data, data.Length); } }
private void Release() { LogSys.Log(LOG_TYPE.INFO, "GmServer release"); DbThreadManager.Instance.Stop(); CenterClientApi.Release(); Thread.Sleep(3000); System.Diagnostics.Process.GetCurrentProcess().Kill(); }
private void Release() { Stop(); CenterClientApi.Release(); Thread.Sleep(3000); //¼òµ¥µã£¬killµô×Ô¼º System.Diagnostics.Process.GetCurrentProcess().Kill(); }
private void Release() { m_TaskDispatcher.StopTaskThreads(); CenterClientApi.Release(); Thread.Sleep(3000); //简单点,直接kill掉自己 System.Diagnostics.Process.GetCurrentProcess().Kill(); }
public bool Send(int dest_handle, IMessage msg) { byte[] data; bool ret = Build(msg, out data); ret = ret && CenterClientApi.SendByHandle(dest_handle, data, data.Length); return(ret); }
private void Release() { LogSys.Log(LOG_TYPE.INFO, "DataCache release"); DataCacheSystem.Instance.Stop(); DbThreadManager.Instance.Stop(); CenterClientApi.Release(); LogSys.Release(); }
internal static void SendDcoreMessage(int handle, JsonMessage msg) { if (s_Inited) { byte[] data = BuildCoreMessage(msg); CenterClientApi.SendByHandle(handle, data, data.Length); } }
private void Release() { room_mgr_.StopRoomThread(); CenterClientApi.Release(); Thread.Sleep(3000); //简单点,直接kill掉自己 System.Diagnostics.Process.GetCurrentProcess().Kill(); }
internal void Init(int port) { InitMessageHandler(); int receiveBufferSize = 64; int sendBufferSize = 64; StringBuilder sb = new StringBuilder(256); if (CenterClientApi.GetConfig("ReceiveBufferSize", sb, 256)) { receiveBufferSize = int.Parse(sb.ToString()); } if (CenterClientApi.GetConfig("SendBufferSize", sb, 256)) { sendBufferSize = int.Parse(sb.ToString()); } m_Config = new NetPeerConfiguration("RoomServer"); m_Config.MaximumConnections = 1024; m_Config.ConnectionTimeout = 5.0f; m_Config.PingInterval = 1.0f; m_Config.ReceiveBufferSize = receiveBufferSize * 1024 * 1024; m_Config.SendBufferSize = sendBufferSize * 1024 * 1024; m_Config.Port = port; m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage); m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); //m_Config.EnableMessageType(NetIncomingMessageType.DebugMessage); //m_Config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage); m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage); if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.DebugMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.DebugMessage"); } if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.VerboseDebugMessage"); } if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.ErrorMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.ErrorMessage"); } if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.WarningMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.WarningMessage"); } m_NetServer = new NetServer(m_Config); m_NetServer.Start(); m_IOThread = new Thread(new ThreadStart(IOHandler)); m_IOThread.Name = "IOHandler"; m_IOThread.IsBackground = true; m_Status = RoomSrvStatus.STATUS_RUNNING; m_IOThread.Start(); RoomPeerMgr.Instance.Init(); Console.WriteLine("Init IOManager OK!"); }
static void Main(string[] args) { #if TEST_CENTER_CLIENT CenterClientApi.HandleNameHandleChangedCallback cb1 = HandleNameHandleChanged; CenterClientApi.HandleMessageCallback cb2 = HandleMessage; CenterClientApi.HandleMessageResultCallback cb3 = HandleMessageResult; CenterClientApi.HandleCommandCallback cb4 = HandleCommand; byte[] bytes = Encoding.ASCII.GetBytes("test test test"); CenterClientApi.Init("csharpclient", args.Length, args, cb1, cb2, cb3, cb4); CenterClientApi.ReloadConfigScript(); CenterClientApi.ReloadConfigScript(); for (; ;) { CenterClientApi.Tick(); Thread.Sleep(10); int handle = CenterClientApi.TargetHandle("ServerCenter"); if (handle > 0) { bool ret = CenterClientApi.SendByHandle(handle, bytes, (ushort)bytes.Length); CenterClientApi.SendCommandByHandle(handle, "output('test test test');"); } } //CenterClientApi.Release(); #else CenterHubApi.HandleNameHandleChangedCallback cb1 = HandleNameHandleChanged2; CenterHubApi.HandleMessageCallback cb2 = HandleMessage2; CenterHubApi.HandleMessageResultCallback cb3 = HandleMessageResult2; CenterHubApi.HandleCommandCallback cb4 = HandleCommand2; byte[] bytes = Encoding.ASCII.GetBytes("test test test"); CenterHubApi.Init("centerhub", args.Length, args, cb1, cb2, cb3, cb4); CenterHubApi.ReloadConfigScript(); CenterHubApi.ReloadConfigScript(); for (; ;) { CenterHubApi.Tick(); Thread.Sleep(10); int handle = CenterHubApi.TargetHandle(0, "hub2world0"); if (handle > 0) { bool ret = CenterHubApi.SendByHandle(0, handle, bytes, (ushort)bytes.Length); CenterHubApi.SendCommandByHandle(0, handle, "output('test test test');"); } handle = CenterHubApi.TargetHandle(1, "hub2world1"); if (handle > 0) { bool ret = CenterHubApi.SendByHandle(1, handle, bytes, (ushort)bytes.Length); CenterHubApi.SendCommandByHandle(1, handle, "output('test test test');"); } } //CenterHubApi.Release(); #endif }
private void Init(string[] args) { m_NameHandleCallback = this.OnNameHandleChanged; m_MsgCallback = this.OnMessage; m_CmdCallback = this.OnCommand; m_MsgResultCallback = this.OnMessageResult; CenterClientApi.Init("store", args.Length, args, m_NameHandleCallback, m_MsgCallback, m_MsgResultCallback, m_CmdCallback); m_Channel = new PBChannel(DashFire.DataStore.MessageMapping.Query, DashFire.DataStore.MessageMapping.Query); m_Channel.DefaultServiceName = "Lobby"; LogSys.Init("./config/logconfig.xml"); DataStoreConfig.Init(); ArkCrossEngine.GlobalVariables.Instance.IsClient = false; FileReaderProxy.RegisterReadFileHandler((string filePath) => { byte[] buffer = null; try { buffer = File.ReadAllBytes(filePath); } catch (Exception e) { LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", e.Message, e.StackTrace); return(null); } return(buffer); }, (string filepath) => { return(File.Exists(filepath)); }); LogSystem.OnOutput += (Log_Type type, string msg) => { switch (type) { case Log_Type.LT_Debug: LogSys.Log(LOG_TYPE.DEBUG, msg); break; case Log_Type.LT_Info: LogSys.Log(LOG_TYPE.INFO, msg); break; case Log_Type.LT_Warn: LogSys.Log(LOG_TYPE.WARN, msg); break; case Log_Type.LT_Error: case Log_Type.LT_Assert: LogSys.Log(LOG_TYPE.ERROR, msg); break; } }; DbThreadManager.Instance.Init(DataStoreConfig.LoadThreadNum, DataStoreConfig.SaveThreadNum); DataOpSystem.Instance.Init(m_Channel); DataCacheSystem.Instance.Init(); LogSys.Log(LOG_TYPE.INFO, "DataStore initialized"); }
public static void Init() { StringBuilder sb = new StringBuilder(256); if (CenterClientApi.GetConfig("DSRequestTimeout", sb, 256)) { s_Instance.m_DSRequestTimeout = uint.Parse(sb.ToString()); } }
internal static void ForwardMessage(int handle, byte[] data) { if (s_Inited) { if (null != data) { CenterClientApi.SendByHandle(handle, data, data.Length); } } }
internal static void ForwardMessage(string name, byte[] data) { if (s_Inited) { if (null != name && null != data) { CenterClientApi.SendByName(name, data, data.Length); } } }
private void Release() { LogSys.Log(LOG_TYPE.INFO, "DataStore release"); DataCacheSystem.Instance.Stop(); DbThreadManager.Instance.Stop(); CenterClientApi.Release(); Thread.Sleep(3000); //简单点,kill掉自己 System.Diagnostics.Process.GetCurrentProcess().Kill(); }
internal void ForwardToWorld(string userSvrName, object msg) { if (!string.IsNullOrEmpty(userSvrName) && null != msg) { int lobbyHandle = CenterClientApi.TargetHandle(userSvrName); if (lobbyHandle > 0) { ForwardToWorld(lobbyHandle, msg); } } }
internal void TransmitToWorld(string userSvrName, string nodeName, NodeMessage msg) { if (!string.IsNullOrEmpty(userSvrName) && !string.IsNullOrEmpty(nodeName) && null != msg) { int lobbyHandle = CenterClientApi.TargetHandle(userSvrName); if (lobbyHandle > 0) { TransmitToWorld(lobbyHandle, nodeName, msg); } } }
internal static void SendNodeMessage(int handle, NodeMessage msg) { if (s_Inited) { byte[] data = BuildNodeMessage(msg); if (null != data) { CenterClientApi.SendByHandle(handle, data, data.Length); } } }
internal static void SendNodeMessage(string name, NodeMessage msg) { if (s_Inited) { byte[] data = BuildNodeMessage(msg); if (null != name && null != data) { CenterClientApi.SendByName(name, data, data.Length); } } }
public bool Send(string dest_name, IMessage msg) { bool ret = false; int handle = CenterClientApi.TargetHandle(dest_name); if (handle != 0) { ret = Send(handle, msg); } return(ret); }
private void OnMessage(uint seq, int source_handle, int dest_handle, IntPtr data, int len) { try { if (IsUnknownServer(source_handle)) { StringBuilder sb = new StringBuilder(256); if (CenterClientApi.TargetName(source_handle, sb, 256)) { string name = sb.ToString(); if (name.StartsWith("NodeJs")) { m_NodeHandles.Add(source_handle); } else if (name.StartsWith("RoomSvr")) { m_RoomSvrHandles.Add(source_handle); } } } byte[] bytes = new byte[len]; Marshal.Copy(data, bytes, 0, len); if (IsNode(source_handle)) { if (!GlobalVariables.Instance.IsWaitQuit) { JsonMessageDispatcher.HandleDcoreMessage(seq, source_handle, dest_handle, bytes); } } else if (IsRoomServer(source_handle)) { m_RoomSvrChannel.Dispatch(source_handle, seq, bytes); } else if (IsBridge(source_handle)) { m_BridgeChannel.Dispatch(source_handle, seq, bytes); } else if (IsStore(source_handle)) { m_StoreChannel.Dispatch(source_handle, seq, bytes); } else if (IsGmServer(source_handle)) { m_GmSvrChannel.Dispatch(source_handle, seq, bytes); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }