Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Vote While Logged In

Discord: .z41n
[VIP] Member
Joined
Aug 3, 2008
Messages
172
Reaction score
26
Hi,

My PHP vote script works fine, except that users are required to log-off in order for the update query to run succesfully.

I removed the logged_in check to see if maybe that alone would allow users to gain NX without having to log off, but it doesn't work. It does, however, update the table temporarily but then reverts back to their original NX amount before voting.

So the issue is that they must be logged off, but was hoping someone could advise how I could make it work while they stay logged in.

My query to update their records is:
PHP:
mysql_query("UPDATE accounts SET nxCredit = nxCredit + '8000' WHERE name='" . mysql_real_escape_string($_POST["name"]) . "'");

Thanks

v83 solaxia-based
 
Mythic Archon
Joined
Jul 2, 2013
Messages
723
Reaction score
70
Hello,

First let me address your initial findings. The reason for the check to see if a player is online is because when a player is online, their data has already been loaded from the database and stored in memory to be used by the game-server. In other words, the data inside the database isn't actively used while a player is in-game; the data inside a database only exists to keep record of player data while a player is offline. When a player logs off, the data inside the database is overwritten with the player's updated data. That said, removing the logged in check will result in player's not being rewarded for voting while in-game because those accredited rewards are overwritten when the player logs out with the player's updated data.

For example, when a player logs in, their data is loaded from the database. Let's say this player had 0 nx credit. When the player logs in, we expect this player to have 0 nx credits. Let's assume this player didn't gain any nx credits in-game while logged in. If this player votes, your script gives the player his/her rewards by updating the accounts table with +8000 nx credits. When the player logs out, the value for nx credits the player had in-game will overwrite the newly gained +8000 nx credit. This is why values are being reverted.


Now let's address what you can do to allow players to vote while logged in. There are two ways you can achieve this: through the use of a (1) socket or (2) worker. (1) With a socket, when you receive a response from GTOP100, you can notify your server to give the player the rewards in-game. This is the method I recommend as players shouldn't have to wait for their rewards. The other method was through a (2) worker. When a player votes, you can have the website insert a record into a table in the database; let's call this column 'pending_vote_rewards'. This table will contain the records of all the players who have voted, but have not received their rewards. On the server end, write a (2) worker that checks 'pending_vote_rewards' on an interval. When a record exists, if the player is still logged in, give them the rewards. If the player has logged out, add it to their character record directly.

Hope this helps!
 
Upvote 0
Discord: .z41n
[VIP] Member
Joined
Aug 3, 2008
Messages
172
Reaction score
26
Hello,

First let me address your initial findings. The reason for the check to see if a player is online is because when a player is online, their data has already been loaded from the database and stored in memory to be used by the game-server. In other words, the data inside the database isn't actively used while a player is in-game; the data inside a database only exists to keep record of player data while a player is offline. When a player logs off, the data inside the database is overwritten with the player's updated data. That said, removing the logged in check will result in player's not being rewarded for voting while in-game because those accredited rewards are overwritten when the player logs out with the player's updated data.

For example, when a player logs in, their data is loaded from the database. Let's say this player had 0 nx credit. When the player logs in, we expect this player to have 0 nx credits. Let's assume this player didn't gain any nx credits in-game while logged in. If this player votes, your script gives the player his/her rewards by updating the accounts table with +8000 nx credits. When the player logs out, the value for nx credits the player had in-game will overwrite the newly gained +8000 nx credit. This is why values are being reverted.


Now let's address what you can do to allow players to vote while logged in. There are two ways you can achieve this: through the use of a (1) socket or (2) worker. (1) With a socket, when you receive a response from GTOP100, you can notify your server to give the player the rewards in-game. This is the method I recommend as players shouldn't have to wait for their rewards. The other method was through a (2) worker. When a player votes, you can have the website insert a record into a table in the database; let's call this column 'pending_vote_rewards'. This table will contain the records of all the players who have voted, but have not received their rewards. On the server end, write a (2) worker that checks 'pending_vote_rewards' on an interval. When a record exists, if the player is still logged in, give them the rewards. If the player has logged out, add it to their character record directly.

Hope this helps!
Zydee

Thank you for this explanation, I have a better idea of how databases work.

I'd like to stick with sockets, but I'm unsure how to implement this exactly. What would the syntax look like for A) GTOP notifying server and B) server updating records whilst player is logged (assuming I would have to save DB then > reload DB with new NX).

Can you push me a little further please?
 
Upvote 0
Back
Top