private static void HandleChatMessageFromClient(int connectionID, byte[] data)
        {
            // Create a new buffer
            ByteBuffer buffer = new ByteBuffer();

            // Read data from package
            buffer.WriteBytes(data);

            // First slot should always be ID
            int packageID = buffer.ReadInteger();
            // Second slot should be the message
            string message = buffer.ReadString();

            // Dispose the buffer
            buffer.Dispose();

            // Write out a line in the console
            Console.WriteLine($"Recieved message from id: {connectionID}, message: {message}");

            // Call the function that broadcasts the message
            ServerTCP.PACKET_ChatmessageToClient(connectionID, message);
        }
Пример #2
0
        private static void ConsoleLoop()
        {
            string line;

            //Console Loop
            while (true)
            {
                line = Console.ReadLine();

                if (line.Contains("/shutdown"))
                {
                    //save();
                    break;
                }
                if (line.Contains("/broadcast"))
                {
                    //Split the message at the space
                    string message = line.Split(' ')[1];
                    //Call the function chatmessage to client with connectionID 0 since that's the server
                    ServerTCP.PACKET_ChatmessageToClient(0, "SERVER BROADCAST: " + message);
                }
            }
        }
Пример #3
0
 static void Main(string[] args)
 {
     InitializeConsoleThread();
     ServerTCP.InitializeServer();
 }