private async Task RunTest(TemporarySessionClient temporaryClient) { try { Debug.Log("Creating session..."); var session = await temporaryClient.SessionPUTAsync(new HiveMP.TemporarySession.Api.SessionPUTRequest()); Debug.Log("Session created " + session.Id); // Create a game lobby. var gameLobbiesClient = new LobbyClient(session.ApiKey); var lobby = await gameLobbiesClient.LobbyPUTAsync(new LobbyPUTRequest { Name = "Test Lobby", MaxSessions = 4, }); Debug.Log("Created game lobby " + lobby.Id); // Test HiveMP Client Connect. Debug.Log("Creating service client..."); var serviceClient = new ServiceClient(""); Debug.Log("Testing if HiveMP Client Connect is enabled..."); if (!(await serviceClient.ServiceEnabledGETAsync(new ServiceEnabledGETRequest()))) { throw new System.Exception("HiveMP Client Connect is not enabled!"); } Debug.Log("Testing if HiveMP Client Connect will execute correctly..."); if (!(await serviceClient.ServiceTestPUTAsync(new ServiceTestPUTRequest { TestName = "test-1" }))) { throw new System.Exception("HiveMP Client Connect test did not pass!"); } Debug.Log("TEST PASS"); _shouldExit = true; } catch (Exception ex) { Debug.LogException(ex); Debug.Log("TEST FAIL"); _shouldExit = true; } }
public static async Task Main(string[] args) { Console.WriteLine("Enter the details for the user account you want to use to sign into HiveMP."); var emailAddress = ReadLine.Read("Email address: "); var password = ReadLine.ReadPassword("Password: "******"API_KEY"); Console.WriteLine("Logging in..."); var sessionClient = new UserSessionClient(apiKey); var session = await sessionClient.AuthenticatePUTAsync(new AuthenticatePUTRequest { Authentication = new AuthenticationRequest { EmailAddress = emailAddress, MarketingPreferenceOptIn = false, Metered = true, PasswordHash = HashPassword(password), ProjectId = null, PromptForProject = null, RequestedRole = null, Tokens = null, TwoFactor = null } }); if (session.AuthenticatedSession == null) { Console.Error.WriteLine("Unable to authenticate with HiveMP!"); return; } Console.WriteLine("Creating a game lobby..."); var lobbyClient = new LobbyClient(session.AuthenticatedSession.ApiKey); var lobby = await lobbyClient.LobbyPUTAsync(new LobbyPUTRequest { Name = "Test Lobby", MaxSessions = 10 }); Console.WriteLine("Joining lobby..."); var connectedSession = await lobbyClient.SessionPUTAsync(new HiveMP.Lobby.Api.SessionPUTRequest { LobbyId = lobby.Id, SessionId = session.AuthenticatedSession.Id, }); Console.WriteLine("Hitting Google Cloud Functions endpoint..."); string gameServerId; using (var client = new HttpClient()) { var response = await client.PutAsync( Environment.GetEnvironmentVariable("GCF_ENDPOINT"), new StringContent(JsonConvert.SerializeObject(new { apiKey = session.AuthenticatedSession.ApiKey, lobbyId = lobby.Id, }), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { Console.WriteLine("Unable to provision game server:"); Console.Error.WriteLine(await response.Content.ReadAsStringAsync()); return; } response.EnsureSuccessStatusCode(); var result = JsonConvert.DeserializeObject <GameServerResponse>(await response.Content.ReadAsStringAsync()); gameServerId = result.GameServerId; } Console.WriteLine("Game server is being provisioned: " + gameServerId); var gameServerClient = new GameServerClient(session.AuthenticatedSession.ApiKey); GameServerPublic gameServerInfo; do { await Task.Delay(2000); gameServerInfo = await gameServerClient.ServerPublicGETAsync(new ServerPublicGETRequest { Id = gameServerId }); Console.WriteLine("Game server status is: " + gameServerInfo.Status); } while (gameServerInfo.Status == "provisioning"); Console.WriteLine("Connect to the game server on:"); foreach (var port in gameServerInfo.ServerPorts) { Console.WriteLine(" - " + gameServerInfo.ServerIpAddress + ":" + port.PublicPort); } }