Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CarlLawl · Feb 03, 2011 at 04:36 PM · multiplayerwwwloginmysql

help with the WWW Class

Ok so I am making a login script that queries a database

it sends of the username and password in a WWWFORM via WWW(url, WWWForm);

how would I go about getting a return ie in php (return true; or return false;) depending on if the details are correct or not

also would this be a practical way about doing it?

Another question I guess I could ask while Im on here that companies it is, if I logged the user in like the above, and in the mysql user table have an isloggedin field which is set to 1 and every few minutes send out another www() to remind the server were still online then use a cron to run another php file every 5 minutes setting isloggedin to 0 that way itll only keep the isloggedin set to 1 if theyre actually on

(so they can log in at the same time, also potentially making a friends list?)

would the above be impractical or out of the question full stop in unity?

the database will be on a dedicated server and online gameplay will be no more than 6 players per match and the game server will be hosted via client only the lobby master server will be on our dedi box

anyway long question but hopefully someone can give me some advice or point me in the right direction!

thanks in advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Feb 03, 2011 at 06:11 PM

That all sounds doable.

In your php, simply echo some sort of code, eg:

(after checking db) if (user_ok) echo "ok"; else echo "no";

or use numbers or some other cryptic code if you worry about hacks.

In the www.text that comes back, you should see that "ok" or "no"

You can then periodically 'ping' the server with a keep-alive script. You might want to use a session id. In fact, you could return the session id if user is 'ok' (instead of just saying 'ok'), or 0 if not ok. Then have the periodic ping send back that session id so you can set the 'online' flag in the db.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CarlLawl · Feb 03, 2011 at 06:27 PM 0
Share

with the session, would it be easier to generate a random number with c# then send it with the username and password and store it all in one go then ive only got to worry about sending back a single int and use a switch for bad username/password/isloggedin etc as for the "ping" you wouldnt say it wouldnt make the game laggy sending off a www "ping" every 2$$anonymous$$utes? also one more question, would you suggest logging out the current player when someone else logs into the same account OR telling the 2nd person logging in that there is already someone playing on that account

avatar image DaveA · Feb 03, 2011 at 10:04 PM 0
Share

Random number: either way, I've done both. If you generate it 'locally' you can also generate an 'authentication' datum too (by encrypting the first number with some known-only-to-you value. Then the php can validate that by running the same encryption and compare what was sent to what was done on the server. If different, someone's trying to hack it. Ping every 2 $$anonymous$$utes shouldn't hurt at all, since you're really just sending a very small 'GET' request and don't even have to process the return. I would probably go with telling the 2nd person that someone is already logged in.

avatar image DaveA · Feb 03, 2011 at 10:06 PM 0
Share

Either case has the potential of annoyance: in the first case, if you log someone out, it's cool if they are the same person, new machine, but otherwise, it's a denial of service, rather rude. In the second, if someone is not legitimately logged in, they could also be denied service. You may want a 'should we log the other session out' option.

avatar image CarlLawl · Feb 04, 2011 at 02:39 AM 0
Share

thank you for your words of wisdom dave, seeing as you seem to know a few amount about the www class maybe i pester you once more in asking how would i go about returning data other than text, i dont know if i was to return back an array for example to see whos online i did have a quick look at the highscores example on unify but if i remember rightly .data is obsolete am i right?

looking at the other potential variables on the documentation im gonna guess itd probably be bytes? but again it doesnt give much information or usage example

thanks for everything so far it has been helpful!

avatar image DaveA · Feb 04, 2011 at 07:09 AM 0
Share

On this I'm not sure. Worst case you could use one of the ascii encodings for data, which bloat the size but at least are still text (you'd pack it in php and unpack it in Unity). But it may be that you can send byte data and just treat it as such. I don't know if any filter is done (say, end-of-line conversion or such). I would guess not. Worth a try. Also I know people have used JSON with WWW, for what that's worth. If the amount of data is small just use text with a compact format. I've used X$$anonymous$$L, but I wouldn't call it compact by any means.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How Do i check for Duplicate username in database 4 Answers

indie db hosting woes 1 Answer

Inventory with a Database 0 Answers

Unity Null Reference Error 1 Answer

yield return WWW.text not downloading??? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges