Beispiel #1
0
 public void Connect(string ip) //port is 25789
 {
     if (!IsConnectedToAServer)
     {
         terminal.AddMessageToTerminal($"Connecting to {ip}...", "System", Color.White);
         socketAddress = new SocketAddress(ip, 25789);
         client.Start(new SocketAddress(ip, 25789));
         client.ConnectToServer();
         IsConnectedToAServer     = true;
         client.OnPacketReceived += OnPacketReceived;
         client.OnPacketSent     += OnPacketSent;
         terminal.AddMessageToTerminal($"Connected !", "System", Color.Green);
     }
     else
     {
         terminal.AddMessageToTerminal("You're already connected to a server.", "System", Color.Red);
     }
 }
Beispiel #2
0
        private void OnKeyPressed(Keys[] keys, KeyboardUtils keyboardUtils)
        {
            if (KeyboardUtils.Contains(keys, Keys.Enter))
            {
                TerminalTexintput.ToggleFocus(this, true);
            }
            if (KeyboardUtils.Contains(keys, Keys.OemQuestion))
            {
                Terminal.AddMessageToTerminal("This is a ne message", "Client", Color.Green);
            }
            if (KeyboardUtils.Contains(keys, Keys.F3))
            {
                DebugManager.ToggleDebugMode(_sprites);
            }
            if (KeyboardUtils.Contains(keys, Keys.F2))
            {
                Texture2D screenshot = RenderManager.RenderSceneToTexture();

                Stream stream = File.Create(@"C:\Users\nicol\Desktop\image.png");
                screenshot.SaveAsPng(stream, (int)Bounds.X, (int)Bounds.Y);
                stream.Dispose();
            }
            if (KeyboardUtils.Contains(keys, Keys.F5))
            {
                Camera.ToggleFollow();
            }
            if (KeyboardUtils.Contains(keys, Keys.F1))
            {
                using (StreamReader sr = new StreamReader("ip.txt"))
                {
                    string ip = sr.ReadLine();
                    NetworkManager.Connect(ip);
                }
            }
            DebugManager.AddEvent("Key pressed : " + new KeysArray(keys), keyboardUtils);
        }