public override OperationResponse Handle(OperationRequest request, SendParameters sendParameters) { GetNebulaCreditsRequest operation = new GetNebulaCreditsRequest(peer.Protocol, request); if (!operation.IsValid) { return(new OperationResponse(request.OperationCode) { ReturnCode = (short)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }); } GameRefId gameRef = new GameRefId(operation.gameRef); var user = application.GetUser(gameRef); if (user == null) { return(new OperationResponse(request.OperationCode) { ReturnCode = (short)ReturnCode.UserNotFound, DebugMessage = string.Format("user with game ref = {0} not found in database", gameRef.value) }); } GetNebulaCreditsResponse responseData = new GetNebulaCreditsResponse { count = user.nebulaCredits }; return(new OperationResponse(request.OperationCode, responseData)); }
public bool ExistsUser(GameRefId inGameRef) { string gameRef = inGameRef.value; var query = Query <DbUserLogin> .EQ(u => u.gameRef, gameRef); return(this.UserLogins.Count(query) > 0); }
public DbUserLogin GetUser(GameRefId inGameRef) { string gameRef = inGameRef.value; var query = Query <DbUserLogin> .EQ(user => user.gameRef, gameRef); return(UserLogins.FindOne(query)); }
/// <summary> /// Send event to client with game ref /// </summary> /// <param name="gameRef">Game ref of player</param> /// <param name="eventData">Event data passed to player</param> public void SendEvent(GameRefId gameRef, EventData eventData) { lock (syncRoot) { foreach (var client in this) { if (client.Value.auth.gameRef == gameRef.value) { client.Value.SendEvent(eventData); break; } } } }
/// <summary> /// Get newbula credits count for game ref /// </summary> /// <param name="gameRefId">Gameref of user for lookup account</param> /// <returns>Number of credits of user</returns> public int GetNebulaCredits(string gameRefId) { GameRefId gameRef = new GameRefId(gameRefId); var user = application.GetUser(gameRef); if (user != null) { return(user.nebulaCredits); } else { return(0); } }
//#if LOCAL /// <summary> /// Add nebula credits to user account and save user in database /// </summary> /// <param name="gameRefId">Gameref of user</param> /// <param name="credits">Number of credits to add (might be less than zero, than credits will be clamped to zero)</param> /// <returns>Status of operation</returns> public bool AddNebulaCredits(string gameRefId, int credits) { GameRefId gameRef = new GameRefId(gameRefId); var user = application.GetUser(gameRef); if (user == null) { return(false); } user.nebulaCredits += credits; if (user.nebulaCredits < 0) { user.nebulaCredits = 0; } application.SaveUser(user); return(true); }
public object AddNebulaCredits(string login, string gameRefId, string characterId, int nebulaCredits) { logger.Info($"{LOG_TAG} => AddNebulaCredits({login}, {gameRefId}, {characterId}, {nebulaCredits})"); GameRefId gameRef = new GameRefId(gameRefId); DbUserLogin user = application.GetUser(gameRef); if (user == null) { return((int)ReturnCode.Fatal); } user.nebulaCredits += nebulaCredits; if (user.nebulaCredits < 0) { user.nebulaCredits = 0; } application.SaveUser(user); application.LogedInUsers.SendEvent(gameRef, new Photon.SocketServer.EventData((byte)LoginEventCode.NebulaCreditsUpdate, new NebulaCreditsUpdateEvent { nebulaCredits = user.nebulaCredits })); return((int)ReturnCode.Ok); }
public DbUserLogin GetUser(GameRefId gameRef) { return(DbUserLogins.GetUser(gameRef)); }