/* returns null if: * - already logged in * - database connection failed * - database authentication failed * - user data is null * - username is null */ public string Login(string address, string username, string password, out ECode ec) { ec = ECode.None; string token = null; IUserPortalServerController_Callback callbackChannel = OperationContext.Current.GetCallbackChannel <IUserPortalServerController_Callback>(); try { // Check credentials against database // int id = DSConnection.AuthenticateCredentials(username, password); if (id != -1) // valid { // Check if already logged in // if (UserRegistry.IsPuidRegistered(username) == false) { // Log in User // User user = DSConnection.GetUser(id); UserSession session = new UserSession(username, address, USER_LIFESPAN, callbackChannel, user); token = UserRegistry.RegisterClient(session); Console.WriteLine("> New Login: @username:{" + username + "} token:{" + token + "}"); } else { // Retrieve existing session token // token = UserRegistry.GetToken(username); ((UserSession)UserRegistry.GetClientSession(token)).CallbackChannel = callbackChannel; // update callback channel Console.WriteLine("> Old Login: @username:{" + username + "} token:{" + token + "}"); } } else { Console.WriteLine("> Failed Login: @username:{" + username + "}"); } } catch (DataServerException ex) { // occurs if any of the database queries fail ec = ex.ErrorCode; } catch (ArgumentNullException) { // occurs if username or user data is null ec = ECode.QueryError; } return(token); }
public void AddUserToPlayerList(string token, string userPuid) { GameSession gs = (GameSession)GameRegistry.GetClientSession(token); if (gs != null) { string userToken = UserRegistry.GetToken(userPuid); if (userToken != null) { gs.AddUserToPlayerList(userPuid, userToken); Console.WriteLine("> Event: @username:{" + userPuid + "} joined @GameServer:{" + gs.PUID + "}"); } else { Console.WriteLine("> Illegal Event: @username:{" + userPuid + "} joined @GameServer:{" + gs.PUID + "}"); Console.WriteLine("> Reason: @username:{" + userPuid + "} has invaild session token:{" + userToken + "}"); } } else { Console.WriteLine("> Illegal Event: @username:{" + userPuid + "} joined unknown GameServer!"); } }
private void ApplyEffect(List <string> targets, AbilityEffect ae, int magnitude) { PlayerSession player = null; foreach (string target in targets) { player = (PlayerSession)PlayerRegistry.GetClientSession(PlayerRegistry.GetToken(target)); if (player != null && player.IsTargetable()) { ApplyEffect(player.PlayerHero, ae, magnitude); } else if (target == Boss.PUID) { ApplyEffect(GameBoss, ae, magnitude); } } }
internal void Trigger_OnPlayerChange(PlayerDetail playerDetail, string userToken) { PlayerSession session = (PlayerSession)PlayerRegistry.GetClientSession(userToken); if (session != null) { IGameServerController_Callback callback = session.CallbackChannel; if (callback != null) { try { callback.GameServer_OnPlayerChange(playerDetail); } catch (CommunicationException ex) { Console.WriteLine("> Failed trigger event: OnPlayerChange\n" + ex.Message); } catch (TimeoutException ex) { Console.WriteLine("> Failed trigger event: OnPlayerChange\n" + ex.Message); } } else { Console.WriteLine("> Failed trigger event: OnPlayerChange\n" + "callback object null!"); } } else { Console.WriteLine("> Failed trigger event: OnPlayerChange\n" + "PlayerSession not found!"); } }