public static async Task Main(string[] args) { var client = new AmongUsClient(); client.OnConnect += () => WriteMessage(new { type = "connect" }); client.OnDisconnect += () => { WriteMessage(new { type = "disconnect" }); Environment.Exit(0); }; client.OnTalkingEnd += () => WriteMessage(new { type = "talkingEnd" }); client.OnTalkingStart += () => WriteMessage(new { type = "talkingStart" }); client.OnGameEnd += () => WriteMessage(new { type = "gameEnd" }); client.OnPlayerDataUpdate += data => WriteMessage(new { type = "gameData", data }); try { await client.Connect(IPAddress.Parse(args[0]), args[1]); } catch (AUException ex) { WriteMessage(new { type = "error", message = ex.Message }); return; } // Trap ctrlc (SIGINT) to disconnect before terminating. Console.CancelKeyPress += (sender, ev) => { ev.Cancel = true; // cancel direct shutdown, so we can disconnect and then kill ourselves client.DisconnectAndExit(); }; // Idle endlessly. while (true) { await Task.Delay(30000); } }
public static async Task engageNewGame(IPAddress region, string game_code, int id, NpgsqlConnection conn) { var client = new AmongUsClient(); clients[game_code] = client; clients.Select(i => $"{i.Key}: {i.Value}").ToList().ForEach(Console.Out.WriteLine); client.OnConnect += () => updateRow(id, UpdateIntention.Activated, conn); client.OnDisconnect += () => { updateRow(id, UpdateIntention.Deactivated, conn); Environment.Exit(0); }; client.OnTalkingEnd += () => updateRow(id, UpdateIntention.SetPlaying, conn); client.OnTalkingStart += () => updateRow(id, UpdateIntention.SetDeliberation, conn); client.OnGameEnd += () => updateRow(id, UpdateIntention.SetLobby, conn); client.OnPlayerDataUpdate += data => updateRow(id, UpdateIntention.NewGameData, conn, parsePlayerData(data)); try { Console.Out.WriteLine("Attempting to connect."); await client.Connect(region, game_code); Console.Out.WriteLine("Completed."); } catch (AUException ex) { WriteMessage(new { type = "error", message = ex.Message }); return; } while (true) { await Task.Delay(30000); } }