private void OnDeviceDisabled(int index) { m_connectButton.gameObject.SetActive(m_inputManager.DeviceCount > 0); Player player = m_playerMenu[index].Player; m_playerMenu[index].gameObject.SetActive(false); if (player != null) { IProgressIndicator progress = m_progress.GetChild(index); progress.IsVisible = true; IGameServer gameServer = Dependencies.GameServer; gameServer.Logoff(m_gSettings.ClientId, player.Id, (error, playerId) => { progress.IsVisible = false; if (gameServer.HasError(error)) { m_notification.ShowError(error); return; } SetDisabledAsLast(index); TryNavigateToMainMenu(); }); } else { SetDisabledAsLast(index); TryNavigateToMainMenu(); } }
private static void LogoffIfNeeded(Action done) { IGameServer server = Dependencies.GameServer; IGlobalSettings gSettings = Dependencies.Settings; server.GetPlayers(gSettings.ClientId, (e0, players) => { if (players.Length == 0) { done(); } else { server.Logoff(gSettings.ClientId, players.Select(p => p.Id).ToArray(), (e1, guid) => { done(); }); } }); }
protected override void OnRequest(ILowProtocol sender, LowRequestArgs request) { RemoteCall rpc; try { rpc = m_serializer.Deserialize <RemoteCall>(request.Data); } catch (Exception e) { Log.Error("Invalid RemoteCall format ", e); //#warning Should force disconnect client #warning This code is not tested sender.Disable(); throw; } switch (rpc.Procedure) { case RemoteCall.Proc.RegisterClient: { RegisterClient(sender, rpc.ClientId); Return(sender, request, new Error(StatusCode.OK)); } break; case RemoteCall.Proc.GetPlayers: m_gameServer.GetPlayers(rpc.ClientId, (error, players) => { Return(sender, request, error, RemoteArg.Create(players)); }); break; case RemoteCall.Proc.GetPlayersByRoomId: m_gameServer.GetPlayers(rpc.ClientId, rpc.Get <Guid>(0), (error, players) => { Return(sender, request, error, RemoteArg.Create(players)); }); break; case RemoteCall.Proc.GetPlayer: m_gameServer.GetPlayer(rpc.ClientId, rpc.Get <Guid>(0), (error, players) => { Return(sender, request, error, RemoteArg.Create(players)); }); break; case RemoteCall.Proc.Login: m_gameServer.Login(rpc.Get <string>(0), rpc.Get <string>(1), rpc.ClientId, (error, playerId, pwdHash) => { Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(pwdHash)); }); break; case RemoteCall.Proc.LoginHash: m_gameServer.Login(rpc.Get <string>(0), rpc.Get <byte[]>(1), rpc.ClientId, (error, playerId) => { Return(sender, request, error, RemoteArg.Create(playerId)); }); break; case RemoteCall.Proc.SignUp: m_gameServer.SignUp(rpc.Get <string>(0), rpc.Get <string>(1), rpc.ClientId, (error, playerId, pwdHash) => { Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(pwdHash)); }); break; case RemoteCall.Proc.Logoff: m_gameServer.Logoff(rpc.ClientId, rpc.Get <Guid>(0), (error, guid) => { Return(sender, request, error, RemoteArg.Create(guid)); }); break; case RemoteCall.Proc.LogoffMultiple: m_gameServer.Logoff(rpc.ClientId, rpc.Get <Guid[]>(0), (error, guids) => { Return(sender, request, error, RemoteArg.Create(guids)); }); break; case RemoteCall.Proc.JoinRoom: m_gameServer.JoinRoom(rpc.ClientId, rpc.Get <Guid>(0), (error, room) => { //Boradcast to room players Return(sender, request, error, RemoteArg.Create(room)); }); break; case RemoteCall.Proc.LeaveRoom: m_gameServer.LeaveRoom(rpc.ClientId, (error) => { //Brodcast to room players Return(sender, request, error); }); break; case RemoteCall.Proc.GetRooms: m_gameServer.GetRooms(rpc.ClientId, rpc.Get <int>(0), rpc.Get <int>(1), (error, rooms) => { Return(sender, request, error, RemoteArg.Create(rooms)); }); break; case RemoteCall.Proc.GetRoom: m_gameServer.GetRoom(rpc.ClientId, (error, room) => { Return(sender, request, error, RemoteArg.Create(room)); }); break; case RemoteCall.Proc.GetRoomById: m_gameServer.GetRoom(rpc.ClientId, rpc.Get <Guid>(0), (error, room) => { Return(sender, request, error, RemoteArg.Create(room)); }); break; case RemoteCall.Proc.CreateRoom: m_gameServer.CreateRoom(rpc.ClientId, rpc.Get <Guid>(0), rpc.Get <GameMode>(1), (error, room) => { //Do not broadcast //client will get rooms list using polling each 10 seconds //or using refres button Return(sender, request, error, RemoteArg.Create(room)); }); break; case RemoteCall.Proc.DestroyRoom: m_gameServer.DestroyRoom(rpc.ClientId, rpc.Get <Guid>(0), (error, guid) => { Return(sender, request, error, RemoteArg.Create(guid)); }); break; case RemoteCall.Proc.CreateBot: m_gameServer.CreateBot(rpc.ClientId, rpc.Get <string>(0), rpc.Get <BotType>(1), (error, playerId, room) => { Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(room)); }); break; case RemoteCall.Proc.CreateBots: m_gameServer.CreateBots(rpc.ClientId, rpc.Get <string[]>(0), rpc.Get <int[]>(1).ToEnum <BotType>(), (error, playerIds, room) => { Return(sender, request, error, RemoteArg.Create(playerIds), RemoteArg.Create(room)); }); break; case RemoteCall.Proc.DestroyBot: m_gameServer.DestroyBot(rpc.ClientId, rpc.Get <Guid>(0), (error, playerId, room) => { Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(room)); }); break; case RemoteCall.Proc.UploadMapData: m_gameServer.UploadMap(rpc.ClientId, rpc.Get <MapInfo>(0), rpc.Get <byte[]>(1), (error) => { Return(sender, request, error); }); break; case RemoteCall.Proc.GetMaps: m_gameServer.GetMaps(rpc.ClientId, (Error error, ByteArray[] mapsInfo) => { Return(sender, request, error, RemoteArg.Create(mapsInfo)); }); break; case RemoteCall.Proc.DownloadMapData: m_gameServer.DownloadMapData(rpc.ClientId, rpc.Get <Guid>(0), (Error error, byte[] mapData) => { Return(sender, request, error, RemoteArg.Create(mapData)); }); break; case RemoteCall.Proc.GetReplays: m_gameServer.GetReplays(rpc.ClientId, (Error error, ByteArray[] replaysInfo) => { Return(sender, request, error, RemoteArg.Create(replaysInfo)); }); break; case RemoteCall.Proc.SetReplay: m_gameServer.SetReplay(rpc.ClientId, rpc.Get <Guid>(0), (error) => { Return(sender, request, error); }); break; case RemoteCall.Proc.SaveReplay: m_gameServer.SaveReplay(rpc.ClientId, rpc.Get <string>(0), (error) => { Return(sender, request, error); }); break; case RemoteCall.Proc.GetStats: m_gameServer.GetStats(rpc.ClientId, (error, serverStats) => { Return(sender, request, error, RemoteArg.Create(serverStats)); }); break; case RemoteCall.Proc.SetReadyToLaunch: m_gameServer.SetReadyToLaunch(rpc.ClientId, rpc.Get <bool>(0), (error, room) => { Return(sender, request, error, RemoteArg.Create(room)); }); break; case RemoteCall.Proc.Launch: m_gameServer.Launch(rpc.ClientId, (error, serverUrl) => { Return(sender, request, error, RemoteArg.Create(serverUrl)); }); break; case RemoteCall.Proc.SendChatMessage: m_gameServer.SendMessage(rpc.ClientId, rpc.Get <ChatMessage>(0), (error, messageId) => { Return(sender, request, error, RemoteArg.Create(messageId)); }); break; } }
private void GetPlayers() { m_progress.IsVisible = true; m_readyToGo = 0; for (int i = 0; i < m_playerMenu.Length; ++i) { m_playerMenu[i].LocalPlayerIndex = i; } for (int i = 0; i < m_playerMenu.Length; ++i) { m_playerMenu[i].Player = null; } IGameServer gameServer = Dependencies.GameServer; gameServer.GetPlayers(m_gSettings.ClientId, (error, players) => { if (gameServer.HasError(error)) { m_progress.IsVisible = false; m_notification.ShowError(error); return; } HandleDevicesChange(); int playersCount = Mathf.Min(m_inputManager.DeviceCount, players.Length); for (int i = 0; i < playersCount; ++i) { m_playerMenu[i].Player = players[i]; } for (int i = 0; i < m_inputManager.DeviceCount; ++i) { m_playerMenu[i].IsVirtualKeyboardEnabled = !m_inputManager.IsKeyboardAndMouse(i); } if (m_inputManager.DeviceCount < players.Length) { List <Guid> logoffPlayers = new List <Guid>(); for (int i = m_inputManager.DeviceCount; i < players.Length; ++i) { logoffPlayers.Add(players[i].Id); } gameServer.Logoff(m_gSettings.ClientId, logoffPlayers.ToArray(), (error2, playerIds) => { m_progress.IsVisible = false; if (gameServer.HasError(error2)) { m_notification.ShowError(error2); return; } }); } else { m_progress.IsVisible = false; } for (int i = players.Length; i < m_inputManager.DeviceCount; ++i) { m_playerMenu[i].TryAutoLogin(); } }); }