Example #1
0
 void IDeprivClient.SetClipboard(string value)
 {
     lock (workerlock)
     {
         if (workerconnected)
         {
             comms.SendMessage(Communicator.SET_CLIPBOARD, value);
         }
     }
 }
Example #2
0
        static void Main()
        {
            CommServer server = new CommServer();

            server.Listen(8888);
            server.OnConnect += delegate()
            {
                Console.WriteLine("An agent connects.");
            };
            server.OnReceive += delegate()
            {
                byte[] data;
                IMsg   msg;
                if (server.TryTake(out msg))
                {
                    MessageToServer mm = msg.Content as MessageToServer;
                    Console.WriteLine($"Receive a message from {mm.PlayerID}");
                    Console.WriteLine($"Message type::{mm.MessageType}");
                    if (mm.MessageType == MessageType.Send)
                    {
                        Console.WriteLine(mm.Message);
                    }
                }
                else
                {
                    Console.WriteLine("fail to dequeue");
                }
            };
            Console.WriteLine("============================");
            Console.ReadLine();

            {
                MessageToOneClient m = new MessageToOneClient();
                m.PlayerID    = 0;
                m.TeamID      = 0;
                m.MessageType = MessageType.ValidPlayer;
                m.Guid        = 888;
                server.SendMessage(m);
                Console.WriteLine("已发送Validplayer");
            }

            Console.ReadLine();
            server.SendMessage(TestMessage(0, MessageType.StartGame));
            Console.WriteLine("已发送StartGame");
            Console.ReadLine();
            for (int i = 0; i < 100; i++)
            {
                server.SendMessage(TestMessage(i, MessageType.Gaming));
                Thread.Sleep(50);
            }
            Console.WriteLine("Gaming");
            Console.ReadLine();
            for (int i = 0; i < 100; i++)
            {
                server.SendMessage(TestMessage(i + 100, MessageType.Gaming));
                Thread.Sleep(50);
            }
            MessageToOneClient m2OC = new MessageToOneClient();

            m2OC.Guid        = 12345;
            m2OC.PlayerID    = 0;
            m2OC.TeamID      = 0;
            m2OC.MessageType = MessageType.Send;
            m2OC.Message     = "Hello world!";
            server.SendMessage(m2OC);
            Console.WriteLine("Msg sent");
            for (int i = 0; i < 100; i++)
            {
                server.SendMessage(TestMessage(i + 200, MessageType.Gaming));
                Thread.Sleep(50);
            }
            server.SendMessage(TestMessage(666, MessageType.EndGame));
            Console.WriteLine("GameOver");
            Console.ReadLine();
            server.Dispose();
            server.Stop();
        }