示例#1
0
        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);
        }
示例#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
        }
 internal static void ForwardMessage(int handle, byte[] data)
 {
     if (s_Inited)
     {
         if (null != data)
         {
             CenterHubApi.SendByHandle(s_WorldId, handle, data, data.Length);
         }
     }
 }
 internal static void SendNodeMessage(int handle, JsonMessage msg)
 {
     if (s_Inited)
     {
         byte[] data = BuildNodeMessage(msg);
         if (null != data)
         {
             CenterHubApi.SendByHandle(s_WorldId, handle, data, data.Length);
         }
     }
 }