Пример #1
0
        private void OnCommand(int worldId, int src, int dest, string command)
        {
            const string c_QuitLobby    = "QuitLobby";
            const string c_ReloadConfig = "ReloadConfig";

            try {
                if (worldId == UserServerConfig.WorldId)
                {
                    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.DefaultUserThread.QueueAction(m_UserProcessScheduler.DoLastSaveUserData);
                            m_GlobalProcessThread.QueueAction(m_GlobalProcessThread.DoLastSaveGlobalData);
                            m_LastWaitQuitTime = TimeUtility.GetLocalMilliseconds();
                            m_WaitQuit         = true;
                        }
                    }
                    else if (0 == command.CompareTo(c_ReloadConfig))
                    {
                        CenterHubApi.ReloadConfigScript();
                        UserServerConfig.Init();
                        LogSys.Log(LOG_TYPE.WARN, "receive {0} command.", command);
                    }
                }
                else
                {
                }
            } catch (Exception ex) {
                LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
            }
        }
Пример #2
0
        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
        }