Monkuar Posted September 14, 2013 Share Posted September 14, 2013 (edited) "I would imagine (but have no pratical experience/knowledge) that a game server most likely handles a lot of the operations/changes that need done in-memory and has some kind of background thread which will periodically save changes to the database. That way it would be able to service all the clients quickly without waiting on the database." This is what Kicken said about updating and stuff via the client for a MMO. What about doing this same logic via Javascript/PHP? How would we temporary save this type of game data and do periodic updates so we don't get any hackers/exploiters? In other words I use a "Attackmob" function each time a user clicks "attack" to swing their sword or hit a monster. This function queries 3 queries and spits out data via AJAX and appends it to the page. [Monster loss of life/etc] So it seems like it's dynamic gameplay. My issue is, is there a way to scratch this ajax stuff temporary while the user is attacking the mob and then once the mob is dead or something, store the data in a temporary array or something then submit it? So we can proccess the mob actions client side [it's a turned based game] for PVP it would be different I know. Problem is, if someone can look at the source code of the page and see how we store this stuff, it's easily hackable/exploitable. [not so much via .exe's and mmorpg's] they have tools to stop looking/reading at memory/etc. But not so much with Javascript, it's really anyone can see the full source eh? Any thoughts guys? Edit: Another issue is the monster's damage is stored in a mysql field, same for it's "Current Health" and other stuff, it would be very easy for a hacker/exploiter to manipulate this if done in javascript. Or I could load up all the server details with javascript and make the "clean" "non-hacking" user play the game with the javascript variables.... It would speed up the process and be faster, but then I could just check if those data's changed via server side [if they decided to hack] and then check it server side each time. This wouldn't really work because of a monsters "Current Health" needs to be saved in a db no matter what... hmmmmmmm Edited September 14, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/ Share on other sites More sharing options...
kicken Posted September 14, 2013 Share Posted September 14, 2013 You need to change how you think about the server-side of things. For instance, rather than using apache as your webserver and running individual PHP scripts for each request, you would use PHP itself as your webserver and have some kind of global store to manage character and mob data. This eliminates the need to query the database on each request as you can just look at what is currently in the global store. You could then setup some kind of system to save important details from that global memory storage to the more permanent database storage periodically. For example maybe once a second or once every x requests or something. Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449439 Share on other sites More sharing options...
Monkuar Posted September 14, 2013 Author Share Posted September 14, 2013 You need to change how you think about the server-side of things. For instance, rather than using apache as your webserver and running individual PHP scripts for each request, you would use PHP itself as your webserver and have some kind of global store to manage character and mob data. This eliminates the need to query the database on each request as you can just look at what is currently in the global store. You could then setup some kind of system to save important details from that global memory storage to the more permanent database storage periodically. For example maybe once a second or once every x requests or something. What kind of global store do you mean? Like similar to how Diablo 2 does it with saved character files? Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449445 Share on other sites More sharing options...
kicken Posted September 14, 2013 Share Posted September 14, 2013 (edited) I just mean some kind of in-memory variable that would be accessible to all clients. Attached is a very quick-n-dirty example of what I mean by having your own server with some kind of global storage. You'd have to put a lot more thought and work into this to make something that functioned well for real-use, but this should illustrate the idea. chat.zip Edited September 14, 2013 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449450 Share on other sites More sharing options...
Monkuar Posted September 17, 2013 Author Share Posted September 17, 2013 (edited) Sorry for the late reply, I thought you ditched the topic The thing about the cookie issue is, it's so EASILY editable. As in compared to program memory or whatnot [alot hard to use a cheat engine/etc] as in-compared to just downloading some cookie editor for firefox/etc. Simple issue I have is.... I have a full inventory system set up with jquery ondrag/drop to update each user_items position column. And I have it spitting it out from PHP to show which inventory slot the item was moved too. My theory is: Instead of each "OnDrop" method the users uses to drag each item on to each slot, it does a $.POST to update it (ajax) in the background and spits out a "Successfully Moved" message. To do this w/o using that ajax, I would need to store HUGE data in the cookie or whatnot then have a javascript timer running every 2-3seconds that just updates the user's character? [Or 1 update query] This would make performance go up by TEN fold, because instead of doing a ajax request on each time the user moves the item, the global save time via 2-3 seconds will update it. The downfall is, if the user is not-active on the browser/session it will do useless updates. I could always timeout a user though after xx seconds ofcourse. Is this kind of what you mean? Problem is the user's inventory is extracted from a different table than the main rpg_users table. so I guess I could just set cookies for each function the user is doing, and if it's =1 update that particular/correct database? Edited September 17, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449914 Share on other sites More sharing options...
kicken Posted September 17, 2013 Share Posted September 17, 2013 The thing about the cookie issue is, ... Who said anything about cookies? Obviously you wouldn't store your game data in a cookie, that is just asking to be hacked. Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449932 Share on other sites More sharing options...
Monkuar Posted September 17, 2013 Author Share Posted September 17, 2013 (edited) Who said anything about cookies? Obviously you wouldn't store your game data in a cookie, that is just asking to be hacked. Yeah, that is my issue. How else can you store the data temporary unless using mysql field? I might be a bit lost, I apologize. I just want to know how those games store their data into "WHAT" then they update it what evey 2-3 seconds? This is where I am lost, what exactly do they store it in? MYSQL route is not what im looking for as in I want someone to beable to farm/kill mobs faster instead of waiting for each ajax request? Are you talking about having a file for each user's character and storing data in there on the server? Isn't fwrite slower than mysql? (Isn't a TON of fwrites gonna be same problem im having as I do with MYSQL) Because I know for Diablo 2, if u get a item, or add a skillpoint or lvl up your d2 filed is saved. So I am assuming they used the http://www.cplusplus.com/reference/cstdio/fwrite/ each time a user kills a mob or gains a item orupdates inventory. Wouldn't that just rape the server as in compared to doing it MYSQL? both would rape the server in my opinion. Edited September 17, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449937 Share on other sites More sharing options...
Monkuar Posted September 17, 2013 Author Share Posted September 17, 2013 (edited) Lol, holy crap. Can't this all be solved with $_SESSION? (Storing it in session data, then submitting it all to db after xxx seconds/etC?) Same logic as old classic RPG games did right? (Except it was in buffer) Edited September 17, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1449942 Share on other sites More sharing options...
ignace Posted September 18, 2013 Share Posted September 18, 2013 Just store it in your database. You can still optimize later. Quote Link to comment https://forums.phpfreaks.com/topic/282143-doing-quick-saves-via-phpclient-side-for-turned-based-game/#findComment-1450019 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.