Example #1
0
        public static void NotifyAll(string message)
        {
            NetworkPacket packet = new NetworkPacket("print");

            packet.WriteString(message);
            packet.SendToClients();
        }
Example #2
0
        public static void Notify(Client client, string message)
        {
            NetworkPacket packet = new NetworkPacket("print");

            packet.WriteString(message);
            packet.SendToClient(client);
        }
        private static void ConnectCallback(IAsyncResult result)
        {
            socket.EndConnect(result);

            if (!IsConnected())
            {
                Console.WriteLine("Could not connect to server");
                return;
            }

            networkStream = socket.GetStream();

            NetworkPacket packet = new NetworkPacket("clientJoinInfo");

            packet.WriteString(name);
            packet.SendToServer();

            networkStream.BeginRead(dataBuffer, 0, dataBuffferSize, ReceiveCallback, null);
        }
Example #4
0
        static CommandRegister()
        {
            Commands.RegisterCommand("startserver", new Command
            {
                Execute = (sender, args) => Server.Start()
            });

            Commands.RegisterCommand("connect", new Command
            {
                argNumber = 1,
                argTypes  = new Type[] { typeof(string) },
                Execute   = (sender, args) => LocalClient.Connect(args[0])
            });

            Commands.RegisterCommand("disconnect", new Command
            {
                Execute = (sender, args) => LocalClient.Disconnect()
            });

            Commands.RegisterCommand("help", new Command
            {
                Execute = (sender, args) => Commands.PrintCommands()
            });

            Commands.RegisterCommand("say", new Command
            {
                argNumber = -1,
                Execute   = (sender, args) =>
                {
                    NetworkPacket packet = new NetworkPacket("say");
                    packet.WriteString(string.Join(" ", args));
                    packet.SendToServer();
                }
            });

            Commands.RegisterCommand("name", new Command
            {
                argNumber = 1,
                argTypes  = new Type[] { typeof(string) },
                Execute   = (sender, args) =>
                {
                    LocalClient.name = args[0];

                    NetworkPacket packet = new NetworkPacket("name");
                    packet.WriteString(args[0]);
                    packet.SendToServer();
                }
            });

            Commands.RegisterCommand("kick", new Command
            {
                argNumber = 1,
                argTypes  = new Type[] { typeof(string) },
                Execute   = (sender, args) =>
                {
                    NetworkPacket packet = new NetworkPacket("kick");
                    packet.WriteString(args[0]);
                    packet.SendToServer();
                }
            });

            Commands.RegisterCommand("stopserver", new Command
            {
                Execute = (sender, args) =>
                {
                    NetworkPacket packet = new NetworkPacket("stopserver");
                    packet.SendToServer();
                }
            });
        }