//Вспомогательные команды серверной части private void handleCommand(string cmd) { try { string[] commands = cmd.Split('#'); int countCommands = commands.Length; for (int i = 0; i < countCommands; i++) { string currentCommand = commands[i]; if (string.IsNullOrEmpty(currentCommand)) { continue; } if (!AuthSuccess) { if (currentCommand.Contains("setname")) { if (setName(currentCommand.Split('|')[1])) { Send("#setnamesuccess"); } else { Send("#setnamefailed"); } } continue; } if (currentCommand.Contains("endsession")) { Server.EndUser(this); return; } if (currentCommand.Contains("success")) { string id = currentCommand.Split('|')[1]; Server.SendFile file = Server.GetFileByID(int.Parse(id)); if (file.ID == 0) { continue; } Send(file.fileBuffer); Server.Files.Remove(file); } if (currentCommand.Contains("sendfileto")) { string[] Arguments = currentCommand.Split('|'); string TargetName = Arguments[1]; int FileSize = Convert.ToInt32(Arguments[2]); string FileName = Arguments[3]; string ske = Arguments[4]; byte[] fileBuffer = new byte[FileSize]; _userHandle.Receive(fileBuffer); Users targetUser = Server.GetUser(TargetName); if (targetUser == null) { //Ошибка что пользователь вышел continue; } Server.SendFile newFile = new Server.SendFile() { ID = Server.Files.Count + 1, FileName = FileName, From = Username, fileBuffer = fileBuffer, FileSize = fileBuffer.Length, sk = ske }; Server.Files.Add(newFile); targetUser.SendFile(newFile, targetUser); } if (currentCommand.Contains("faild")) { string id = currentCommand.Split('|')[1]; Server.SendFile file = Server.GetFileByID(int.Parse(id)); if (file.ID == 0) { //ошибка если файл отсутствует continue; } Server.Files.Remove(file); } } } catch { } }
private void handleCommand(string cmd) { try { string[] commands = cmd.Split('#'); int countCommands = commands.Length; for (int i = 0; i < countCommands; i++) { string currentCommand = commands[i]; if (string.IsNullOrEmpty(currentCommand)) { continue; } if (!AuthSuccess) { if (currentCommand.Contains("setname")) { if (setName(currentCommand.Split('|')[1])) { Send("#setnamesuccess"); } else { Send("#setnamefailed"); } } continue; } if (currentCommand.Contains("yy")) { string id = currentCommand.Split('|')[1]; Server.FileD file = Server.GetFileByID(int.Parse(id)); if (file.ID == 0) { SendMessage("Ошибка при передаче файла...", "1"); continue; } Send(file.fileBuffer); Server.Files.Remove(file); } if (currentCommand.Contains("message")) { string[] Arguments = currentCommand.Split('|'); Server.SendGlobalMessage($"[{_userName}]: {Arguments[1]}", "Black"); continue; }//sENDfile //... if (currentCommand.Contains("endsession")) { Server.EndUser(this); return; } if (currentCommand.Contains("sendfileto")) { string[] Arguments = currentCommand.Split('|'); string TargetName = Arguments[1]; int FileSize = int.Parse(Arguments[2]); string FileName = Arguments[3]; byte[] fileBuffer = new byte[FileSize]; _userHandle.Receive(fileBuffer); User targetUser = Server.GetUser(TargetName); if (targetUser == null) { SendMessage($"Пользователь {FileName} не найден!", "Black"); continue; } Server.FileD newFile = new Server.FileD() { ID = Server.Files.Count + 1, FileName = FileName, From = Username, fileBuffer = fileBuffer, FileSize = fileBuffer.Length }; Server.Files.Add(newFile); targetUser.SendFile(newFile, targetUser); } if (currentCommand.Contains("private")) { string[] Arguments = currentCommand.Split('|'); string TargetName = Arguments[1]; string Content = Decrypt(Arguments[2].Trim()); User targetUser = Server.GetUser(TargetName); if (targetUser == null) { SendMessage($"Пользователь {TargetName} не найден!", "Red"); continue; } Console.WriteLine($"-[Отправлено][{TargetName}]: {Content}"); Console.WriteLine($"-[Получено][{Username}]: {Content}"); Content = Encrypt(Content); PrivateMessage($"-[Отправлено][{TargetName}]:", $" {Content}", "Black"); targetUser.PrivateMessage($"-[Получено][{Username}]:", $" {Content}", "Black"); continue; } } } catch (Exception exp) { Console.WriteLine("Error with handleCommand: " + exp.Message); } }
private void handleCommand(string cmd) { Console.WriteLine("Recieved the message " + _userRole + " " + _userName); try { string[] commands = cmd.Split('#'); int countCommands = commands.Length; if (_userRole == "bot") { for (int i = 0; i < countCommands; i++) { string currentCommand = commands[i]; if (currentCommand.Contains("techies")) { Server.SendGlobalMessage($"{_userName}: {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("looting money")) { Server.SendGlobalMessage($"{_userName}: {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("donate first")) { Server.SendGlobalMessage($"{_userName}: {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("go")) { Server.SendGlobalMessage($"{_userName}: {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("talk")) { Server.SendGlobalMessage($"{_userName}: {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("guess my, 1 to 100? enter the number:")) { Server.SendGlobalMessage($"{_userName}: guess my, 1 to 100? enter the number:", "Red"); } if (currentCommand.Contains("u were right")) { Server.SendGlobalMessage($"{_userName}: u were right", "Red"); } if (currentCommand.Contains("bigger")) { Server.SendGlobalMessage($"{_userName}: mine number is bigger", "Red"); } if (currentCommand.Contains("smaller")) { Server.SendGlobalMessage($"{_userName}: mine number is smaller", "Red"); } if (currentCommand.Contains("enter a number")) { Server.SendGlobalMessage($"{_userName}: it is not a number. Enter correctly", "Red"); } if (currentCommand.Contains("roulette")) { string[] temp = currentCommand.Split('|'); Server.SendGlobalMessage($"{_userName}: {temp[1]} {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("start")) { string[] temp = currentCommand.Split('|'); Server.SendGlobalMessage($"{_userName}: {temp[1]} {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("making shot")) { string[] temp = currentCommand.Split('|'); Server.SendGlobalMessage($"{_userName}: {temp[1]} {Answer(currentCommand)}", "Red"); } if (currentCommand.Contains("result")) { string[] temp = currentCommand.Split('|'); string status = Answer(currentCommand); if (status == "alive") { Server.SendGlobalMessage($"{_userName}: Фартовый день для {temp[1]}, стимюзер выжил!", "Red"); } else { Server.SendGlobalMessage($"{_userName}: Помянем {temp[1]}, земля металлом...", "Red"); } } if (currentCommand.Contains("weather")) { Server.SendGlobalMessage($"{_userName}: {Answer(currentCommand)}", "Red"); } } } else { for (int i = 0; i < countCommands; i++) { string currentCommand = commands[i]; if (string.IsNullOrEmpty(currentCommand)) { continue; } if (!AuthSuccess) { if (currentCommand.Contains("setname")) { if (setName(currentCommand.Split('|')[1])) { Send("#setnamesuccess"); } else { Send("#setnamefailed"); } } continue; } if (currentCommand.Contains("yy")) { string id = currentCommand.Split('|')[1]; Server.FileD file = Server.GetFileByID(int.Parse(id)); if (file.ID == 0) { SendMessage("Ошибка при передаче файла...", "1"); continue; } Send(file.fileBuffer); Server.Files.Remove(file); } if (currentCommand.Contains("message")) { string[] Arguments = cmd.Split('|'); /*if (Arguments[1].Contains("gaben")) * { Server.SendGlobalMessage($"{Arguments[1]}", "Black"); } * else */{ Server.SendGlobalMessage($"[{_userName}]: {Arguments[1]}", "Black"); } continue; } if (currentCommand.Contains("endsession")) { Server.EndUser(this); return; } if (currentCommand.Contains("sendfileto")) { string[] Arguments = currentCommand.Split('|'); string TargetName = Arguments[1]; int FileSize = int.Parse(Arguments[2]); string FileName = Arguments[3]; byte[] fileBuffer = new byte[FileSize]; _userHandle.Receive(fileBuffer); User targetUser = Server.GetUser(TargetName); if (targetUser == null) { SendMessage($"Пользователь {FileName} не найден!", "Black"); continue; } Server.FileD newFile = new Server.FileD() { ID = Server.Files.Count + 1, FileName = FileName, From = Username, fileBuffer = fileBuffer, FileSize = fileBuffer.Length }; Server.Files.Add(newFile); targetUser.SendFile(newFile, targetUser); } if (currentCommand.Contains("private")) { string[] Arguments = currentCommand.Split('|'); string TargetName = Arguments[1]; string Content = Arguments[2]; User targetUser = Server.GetUser(TargetName); if (targetUser == null) { SendMessage($"Пользователь {TargetName} не найден!", "Red"); continue; } SendMessage($"-[Отправлено][{TargetName}]: {Content}", "Black"); targetUser.SendMessage($"-[Получено][{Username}]: {Content}", "Black"); continue; } if (currentCommand.Contains("setname")) { Console.Write($"{_userName} changing nickname:"); string[] Arguments = currentCommand.Split('|'); Console.WriteLine($"to {Arguments[1]}"); if (setName(Arguments[1])) { //Console.WriteLine($"{_userName}"); Send($"#newname|{_userName}"); //Server.SendUserList(); } else { Send("#setnamefailed"); } continue; } if (currentCommand.Contains("ban_tinkera")) { bool c = false; for (int j = 0; j < Server.UserList.Count; j++) { if (Server.UserList[j].Userrole.Contains("admin")) { SendMessage($"There could be only 1 admin", "Red"); c = true; } } if (c == false) { this._userRole = "admin"; Server.SendGlobalMessage($"{this._userName} role switched to {this._userRole}", "blue"); Server.SendUserList(); } continue; } if (currentCommand.Contains("kick")) { if (this._userRole.StartsWith("admin")) { string[] kick = cmd.Split('|'); for (int j = 0; j < Server.UserList.Count; j++) { if (Server.UserList[j].Username == kick[2]) { Server.EndUser(Server.UserList[j]); } else { Console.WriteLine("no users with such nickname"); } } } else { Server.SendGlobalMessage("You are not an admin,bruv", "Red"); } } if (currentCommand.Contains("bot_enter")) { //Server.NewUser(new User(this._userHandle) { Username = "******", Userrole="bot" }); //new Bot(handle_bot); } if (currentCommand.Contains("davai")) { Server.SendUserList(); } continue; } } } catch (Exception exp) { Console.WriteLine("Error with handleCommand: " + exp.Message); } }