/// <summary> /// Starts up the client. /// </summary> public static void Init() { SysConsole.Output(OutputType.INIT, "Loading client..."); Username = Program.GetSetting("username"); SysConsole.Output(OutputType.INFO, "Username: "******"Invalid username!"); Process.GetCurrentProcess().Kill(); } SysConsole.Output(OutputType.INIT, "Loading command engine (Frenetic)..."); ClientOutputter output = new ClientOutputter(); ClientCommands.Init(output); ClientCVar.Init(output); SysConsole.Output(OutputType.INIT, "Loading window..."); Window = new GameWindow(800, 600, new GraphicsMode(32, 24, 0 /* TODO: Are these values good? */, ClientCVar.r_antialiasing.ValueI), Program.GameName, GameWindowFlags.FixedWindow); Window.UpdateFrame += new EventHandler <FrameEventArgs>(Window_UpdateFrame); Window.RenderFrame += new EventHandler <FrameEventArgs>(Window_RenderFrame); Window.Closed += new EventHandler <EventArgs>(Window_Closed); Window.Load += new EventHandler <EventArgs>(Window_Load); Window.KeyPress += new EventHandler <KeyPressEventArgs>(KeyHandler.PrimaryGameWindow_KeyPress); Window.KeyUp += new EventHandler <KeyboardKeyEventArgs>(KeyHandler.PrimaryGameWindow_KeyUp); Window.KeyDown += new EventHandler <KeyboardKeyEventArgs>(KeyHandler.PrimaryGameWindow_KeyDown); Window.MouseDown += new EventHandler <MouseButtonEventArgs>(KeyHandler.Mouse_ButtonDown); Window.MouseUp += new EventHandler <MouseButtonEventArgs>(KeyHandler.Mouse_ButtonUp); Window.MouseWheel += new EventHandler <MouseWheelEventArgs>(KeyHandler.Mouse_Wheel); SysConsole.Output(OutputType.INIT, "Running window startup sequence..."); Window.Run(60, 60); }
public void GetClientInf(ClientCommands command) { byte[] length = new byte[sizeof(ulong)]; networkStream.Read(length, 0, length.Length); byte[] message = new byte[BitConverter.ToUInt64(length, 0)]; networkStream.Read(message, 0, message.Length); ProcessingRequest(command, message); }
/// <summary> /// Start up and run the server. /// </summary> public void StartUp(string args) { Files.Init(); SysConsole.Output(OutputType.CLIENTINIT, "Launching as new client, this is " + (this == Central ? "" : "NOT ") + "the Central client."); SysConsole.Output(OutputType.CLIENTINIT, "Loading command system..."); Commands = new ClientCommands(); Commands.Init(new ClientOutputter(this), this); SysConsole.Output(OutputType.CLIENTINIT, "Loading CVar system..."); CVars = new ClientCVar(); CVars.Init(this, Commands.Output); SysConsole.Output(OutputType.CLIENTINIT, "Loading default settings..."); if (Files.Exists("clientdefaultsettings.cfg")) { string contents = Files.ReadText("clientdefaultsettings.cfg"); Commands.ExecuteCommands(contents); } Commands.ExecuteCommands(args); SysConsole.Output(OutputType.CLIENTINIT, "Generating window..."); DisplayDevice dd = DisplayDevice.Default; Window = new GameWindow(CVars.r_width.ValueI, CVars.r_height.ValueI, new GraphicsMode(24, 24, 0, 0), Program.GameName + " v" + Program.GameVersion + " (" + Program.GameVersionDescription + ")", GameWindowFlags.Default, dd, 4, 3, GraphicsContextFlags.ForwardCompatible); Window.Load += new EventHandler <EventArgs>(Window_Load); Window.RenderFrame += new EventHandler <FrameEventArgs>(Window_RenderFrame); Window.Mouse.Move += new EventHandler <MouseMoveEventArgs>(MouseHandler.Window_MouseMove); Window.KeyDown += new EventHandler <KeyboardKeyEventArgs>(KeyHandler.PrimaryGameWindow_KeyDown); Window.KeyPress += new EventHandler <KeyPressEventArgs>(KeyHandler.PrimaryGameWindow_KeyPress); Window.KeyUp += new EventHandler <KeyboardKeyEventArgs>(KeyHandler.PrimaryGameWindow_KeyUp); Window.Mouse.WheelChanged += new EventHandler <MouseWheelEventArgs>(KeyHandler.Mouse_Wheel); Window.Mouse.ButtonDown += new EventHandler <MouseButtonEventArgs>(KeyHandler.Mouse_ButtonDown); Window.Mouse.ButtonUp += new EventHandler <MouseButtonEventArgs>(KeyHandler.Mouse_ButtonUp); Window.Location = new Point(0, 0); Window.WindowState = CVars.r_fullscreen.ValueB ? WindowState.Fullscreen : WindowState.Normal; Window.Resize += Window_Resize; Window.Closed += Window_Closed; Window.ReduceCPUWaste = true; OnVsyncChanged(CVars.r_vsync, null); if (CVars.r_maxfps.ValueD < 1.0) { CVars.r_maxfps.Set("60"); } if (CVars.r_maxfps.ValueD > 200.0) { Window.Run(1); } else { Window.Run(1, CVars.r_maxfps.ValueD); } }
//==================================================================================================== //Услуга, запрашиваемая клиентом public ClientCommands GetCommand() { ClientCommands currCommand = ClientCommands.EX; try { byte[] command = new byte[Client.command_length]; networkStream.Read(command, 0, 1); currCommand = (ClientCommands)command[0]; } catch (Exception error) { Console.Error.WriteLine(error.Message); } return(currCommand); }
public ServerViewModel() { Server = new Server(IPAddress.Any); Server.ClientConnected += Server_ClientConnected; Server.ClientDisconnected += Server_ClientDisconnected; Server.MessageReceived += Server_MessageReceived; Server.OnPropertyChanged += Server_OnPropertyChanged; Server.Start(); Audio = new AudioCommands(Server, "Audio"); Visual = new VisualCommands(Server, "Visuals"); Windows = new WindowsCommands(Server, "Windows"); Client = new ClientCommands(Server, "Client"); CMD = new CMDCommands(Server, "CMD"); Task.Run(() => new ServerDiscovery("gang?", "Dopple gang").Discover()); }
//==================================================================================================== //Вызывает метод обраблтки пользовательского запроса private void ProcessingRequest(ClientCommands recieve_command, byte[] message) { switch (recieve_command) { case ClientCommands.LOAD: { LOAD_Send_Message(message); break; } case ClientCommands.SEND: { SEND_Send_Message(message); break; } } }
//==================================================================================================== public void Handler() { try { ClientCommands currCommand = GetCommand(); switch (currCommand) { case ClientCommands.AUTH: { GetClientInfHash(currCommand); break; } case ClientCommands.REG: { GetClientInfHash(currCommand); break; } case ClientCommands.LOAD: { GetClientInf(currCommand); break; } case ClientCommands.SEND: { GetClientInf(currCommand); break; } case ClientCommands.EX: { Disconnect(); break; } } } catch (Exception error) { Console.Error.WriteLine(error.Message); Disconnect(); return; } }
public void GetClientInfHash(ClientCommands command) { try { byte[] login_hash = null; FileProtocolReader.Read(ref login_hash, networkStream); byte[] password_hash = null; FileProtocolReader.Read(ref password_hash, networkStream); ToUserHash(command, login_hash, password_hash); } catch (Exception error) { Console.Error.WriteLine(error.Message); Disconnect(); return; } }
/// <summary> /// The primary tick entry point from the OpenGL window. /// </summary> /// <param name="sender">The sending object</param> /// <param name="e">The frame event details, including delta timing</param> static void Window_UpdateFrame(object sender, FrameEventArgs e) { Delta = ((double)Ticker.ElapsedTicks) / ((double)Stopwatch.Frequency); Ticker.Reset(); Ticker.Start(); try { GlobalTickTime += Delta; MouseHandler.Tick(); KeyHandler.Tick(); UIConsole.Tick(); ClientCommands.Tick(); ClientNetworkBase.Tick(); TickWorld(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / updateframe: " + ex.ToString()); } }
public static uint getClientCommandUInt(ClientCommands cCom) { switch (cCom) { case ClientCommands.RequestCompareVersionNumber: return(0); case ClientCommands.SubmitUserName: return(1); case ClientCommands.SubmitPassword_ExistingUser: return(2); case ClientCommands.SubmitPassword_NewUser: return(3); case ClientCommands.ClientError: return(4); case ClientCommands.RequestOnlineUserList: return(5); case ClientCommands.RequestSendMessage: return(6); default: throw new Exception("Unknown client command (" + cCom + ")."); } }
//==================================================================================================== //Конвертирует байты в объект User public void ToUserHash(ClientCommands recieve_command, byte[] login, byte[] password) { this.user_inf = new User(login, password); switch (recieve_command) { case ClientCommands.AUTH: { AUTH_Send_Message(); break; } case ClientCommands.REG: { REG_Send_Message(); break; } default: Disconnect(); break; } }
private byte[] ConvertToBytes(string message, ClientCommands command) { //first, add number of bytes List<byte> requestBuffer = new List<byte>(); requestBuffer.AddRange(BitConverter.GetBytes((int)message.Length)); requestBuffer.AddRange(BitConverter.GetBytes((Int16)command)); requestBuffer.AddRange(Encoding.GetEncoding(1251).GetBytes(message)); return requestBuffer.ToArray(); }
private void SendCommandTo(ClientCommands command, ConnectionInfo ci) { byte[] response = new byte[bufferSize]; response = ConvertToBytes("", command); SendBySocket(ci, response); }
private byte[] ConvertToBytes(ClientCommands command) { return BitConverter.GetBytes((Int16)command); }
private static void WorkWith(string request, ClientCommands command) { string[] requests = request.Split('~'); switch (command) { case ClientCommands.Login: loginresult(IsSuccessfulLogin(requests[1])); break; case ClientCommands.CheckLogin: checkloginresult(IsSuitable(requests[1])); break; case ClientCommands.GetUsersByPattern: getusersbypatternresult(ReturnStringOfUsers(requests[1])); break; case ClientCommands.ChangeUserStatus: // do nothing break; case ClientCommands.FriendRequest: // do nothing break; case ClientCommands.RequestForSystemMessages: requestforsystemmessagesresult(requests[1]); break; case ClientCommands.ReadMessages: // do nothing break; case ClientCommands.SuccessfulFriendRequest: acceptedfriendsrequestsresult(requests[1]); break; case ClientCommands.RequestForFriendsList: requestforfriendslistresult(requests[1]); break; case ClientCommands.Message: onmessagereceived(Concatinations(request, 2), int.Parse(requests[1])); break; case ClientCommands.ServerOffline: serveroffline(); break; case ClientCommands.GetHistory: onhistoryreceived(requests[1]); break; case ClientCommands.GetInformation: oninformationreceived(requests[1]); break; case ClientCommands.DeleteFriend: ondeletedfriend(int.Parse(requests[1])); break; default: break; } }
public ClientCommandInfo(ClientCommands cmd, params object[] args) { Command = cmd.ToString(); Params = args; }
private void SendCommandToAll(ClientCommands command) { byte[] response = new byte[bufferSize]; response = ConvertToBytes("", command); foreach (ConnectionInfo connection in connections) { SendBySocket(connection, response); } }
/// <summary> /// Updates the console, called every tick. /// </summary> public static void Tick() { KeyHandlerState KeyState = KeyHandler.GetKBState(); // Update open/close state if (KeyState.TogglerPressed) { Open = !Open; if (Open) { MouseWasCaptured = MouseHandler.MouseCaptured; MouseHandler.ReleaseMouse(); RecentSpot = RecentCommands.Count; } else { if (MouseWasCaptured) { MouseHandler.CaptureMouse(); } Typing = ""; TypingText = ""; TypingCursor = 0; } } if (Open) { extralines = 0; LineBack = 0; // flicker the cursor keymark_delta += ClientMain.Delta; if (keymark_delta > 0.5f) { keymark_add = !keymark_add; keymark_delta = 0f; } // handle backspaces if (KeyState.InitBS > 0) { string partone = TypingCursor > 0 ? TypingText.Substring(0, TypingCursor) : ""; string parttwo = TypingCursor < TypingText.Length ? TypingText.Substring(TypingCursor) : ""; if (partone.Length > KeyState.InitBS) { partone = partone.Substring(0, partone.Length - KeyState.InitBS); TypingCursor -= KeyState.InitBS; } else { TypingCursor -= partone.Length; partone = ""; } TypingText = partone + parttwo; } // handle input text KeyState.KeyboardString = KeyState.KeyboardString.Replace("\t", " "); if (KeyState.KeyboardString.Length > 0) { if (TypingText.Length == TypingCursor) { TypingText += Utilities.CleanStringInput(KeyState.KeyboardString); } else { if (KeyState.KeyboardString.Contains('\n')) { string[] lines = KeyState.KeyboardString.Split(new char[] { '\n' }, 2); TypingText = TypingText.Insert(TypingCursor, Utilities.CleanStringInput(lines[0])) + "\n" + Utilities.CleanStringInput(lines[1]); } else { TypingText = TypingText.Insert(TypingCursor, Utilities.CleanStringInput(KeyState.KeyboardString)); } } TypingCursor += KeyState.KeyboardString.Length; while (TypingText.Contains('\n')) { int index = TypingText.IndexOf('\n'); string input = TypingText.Substring(0, index); if (index + 1 < TypingText.Length) { TypingText = TypingText.Substring(index + 1); TypingCursor = TypingText.Length; } else { TypingText = ""; TypingCursor = 0; } WriteLine("] " + input); RecentCommands.Add(input); if (RecentCommands.Count > MaxRecentCommands) { RecentCommands.RemoveAt(0); } RecentSpot = RecentCommands.Count; ClientCommands.ExecuteCommands(input); } } // handle copying if (KeyState.CopyPressed) { if (TypingText.Length > 0) { System.Windows.Forms.Clipboard.SetText(TypingText); } } // handle cursor left/right movement if (KeyState.LeftRights != 0) { TypingCursor += KeyState.LeftRights; if (TypingCursor < 0) { TypingCursor = 0; } if (TypingCursor > TypingText.Length) { TypingCursor = TypingText.Length; } keymark_add = true; keymark_delta = 0f; } // handle scrolling up/down in the console if (KeyState.Pages != 0) { ScrolledLine -= (int)(KeyState.Pages * ((float)ClientMain.Window.Height / 2 / FontSet.Standard.font_default.Height - 3)); } ScrolledLine -= MouseHandler.MouseScroll; if (ScrolledLine > 0) { ScrolledLine = 0; } if (ScrolledLine < -Lines + 5) { ScrolledLine = -Lines + 5; } // handle scrolling through commands if (KeyState.Scrolls != 0) { RecentSpot -= KeyState.Scrolls; if (RecentSpot < 0) { RecentSpot = 0; TypingText = RecentCommands[0]; } else if (RecentSpot >= RecentCommands.Count) { RecentSpot = RecentCommands.Count; TypingText = ""; } else { TypingText = RecentCommands[RecentSpot]; } TypingCursor = TypingText.Length; } // update the rendered text Typing = ">" + TypingText; } else // !Open { if (extralines > 0) { LineBack -= ClientMain.Delta; if (LineBack <= 0) { extralines--; LineBack = 3f; } } } }
private byte[] ConvertToBytes(int len, ClientCommands command) { List<byte> requestBuffer = new List<byte>(); requestBuffer.AddRange(BitConverter.GetBytes(len)); requestBuffer.AddRange(BitConverter.GetBytes((Int16)command)); return requestBuffer.ToArray(); }