public static void Main(string[] args) { var user = new UserConsole(); var createUser = ParseArgs(args, user); var(api, userKey) = Create(createUser); user.SendMessage("API Key = " + api.APIKey); user.SendMessage("User Key = " + userKey); var tests = new Dictionary <string, TestDelegate>(); tests["psate"] = TestPaste; tests["list"] = TestList; tests["delete"] = TestDelete; tests["user"] = TestUser; tests["raw"] = TestRaw; while (true) { try { user.SendMessage(); user.SendMessage(); var testQuery = user.QueryInput("Enter Test", tests, pair => pair.Key, true); if (testQuery.Breaked == true) { continue; } var test = testQuery.Value.Value; test(user, api, userKey); } catch (UserInputReturnException) { } catch (Exception e) { user.SendMessage(string.Concat(e)); } } }
public void Run(UserConsole user) { Instance = this; this.Console = user; var tcpClient = new TcpClient(); tcpClient.NoDelay = true; tcpClient.Connect(new IPEndPoint(IPAddress.Parse("124.58.147.98"), 1653)); var client = new NetworkManager(tcpClient); new Thread(() => { try { while (true) { client.ReadPackets(); if (client.CloseMessage != null) { user.SendMessage($"Network Closed : {client.CloseMessage}"); return; } else { client.Tick(); Thread.Sleep(10); } } } catch (Exception e) { user.SendMessage(e.ToString()); } }).Start(); try { var loginToken = Guid.NewGuid().ToString(); var displayName = user.ReadInput("Enter DisplayName"); client.SendPacket(new PacketLoginRequest() { LoginToken = loginToken, DisplayName = displayName }); while (true) { var line = user.ReadInput(); client.SendPacket(new PacketChat() { Message = line }); } } catch (Exception e) { user.SendMessage(e.ToString()); } }