Photon Server + MySQL

edited May 2011 in Photon Server
Hi All,

I am reasonably new to using Photon, i would like some help in terms of hooking the photon server into MySQL, i would like to use it in an MMO.

I would like to update information from the server to the SQL database periodically, for example keeping each players stat's, position info, etc, updated in the Database.

1) I would like the option of initiating this client side, could this be done using custom operations? if so plz point me to some documentation or an example of a custom op.

2) and server side? is there an update method / main loop somewhere in the server code? (Photon.MmoDemo.Server) or (Photon.MmoDemo.Common)

3) or should i create an entirely new photon application for the task? :|

Any help / Documentation links / Opinions will help greatly :)

Thanks

Comments

  • Question: is your MMO going to be a seamless world where everyone could see anyone else if close enough? Or are you using areas / rooms to organize players?

    1) We don't have the tutorial finished. It was planned as part 3 of the "Hello World" tutorials. The "Adding Operations to Lite" is not tutorial like but should get you there, too. Open the Lite.sln from the server SDK and check out the source where operations are used.
    Client side, you can take a look at the LitePeerSource.cs. It shows how OpJoin and OpRaiseEvent are done with OpCustom() calls. Find it, e.g. in the Unity Client SDK: v6-2-0_SDK.zip\demo-realtime-unity\Assets\Photon\

    Custom operations work the exact same way as all operations we built in to Lite and the MMO application.

    2) Server programming is usually done without a main loop. To perform for many users, the logic is triggered by operations. You can schedule messages so "simulate" a main loop or trigger actions within a room, e.g.. The LiteLobby application does this in LiteLobbyRoom.cs.
    The MMO logic is build differently and does not have a single object where you could loop.

    3) As you're beginning with Photon, start with the included applications. Your project should extend those to keep their source un-changed, which makes updates easier. Once you hit any limitations, you can still refactor our code or start with your own projects based on what you learned.
  • Thanks for the quick reply!

    The game is mostly going to be a seamless world, i am using the MMO components from Unity island, along with the MMO server component.

    I have gotten to the stage where i think i need to change server code to create a custom operation to export data to the SQL Server. Having a look through your reply i think i'm on the right path, I will have look into the adding Operations link you have given me. :D
  • I still smacking my head against a wall trying to figure it out :P

    Could you please provide some sample code and which .cs files i put them in for the below example.

    Client: Photon.MmoDemo.Client.Unity3D
    Server: Photon.MmoDemo.Server

    Client: needs to send data string 'currentPosition'
    Server: needs to execute 'SQLCommands' with the data 'currentPosition'

    I think this would help others as well as myself get our heads around custom ops :)
  • I'm sorry, but we can't support you with custom code at the moment.

    In general: Why do you want to send the position as String?
    - Clients already send the position and the server knows it. You can grab the values there anytime needed.

    I hope you don't plan to save the current position to the DB on each position update. If you want to persist the last position an avatar has in a game session, then save the position in the OnDisconnect of the Peer class.
  • Caroz, do you have a problem saving data in MySQL?
  • No, i can save the data when connecting directly to the SQL server from unity, but i don't want to do that.

    Tobias,

    I would like to pass information like username and password to the photon server, then have it send back available characters for that account, then once a character is selected client side, it then loads the last know location of that character into the world.

    I have working code for this, but it is outside of photon and is directly connecting too the SQL database from the client. Ideally i would like to route this through Photon. I suppose i maybe asking Photon to do something outside the scope in which it was developed for? in which case i could just write a custom server for authentication an character selection. Or is this something i can do in Photon?
  • The code should actually work more or less directly over there, but you won't route it then anymore.
    You would send a request (operation) to the server, likely login, the server will then lookup the account and if its valid get the chars for the account and send back a hashtable with the relevant information for example

    Its best to always keep in mind that the client should always only ask the server to do something, never try to do it himself. that way you have all the security critical code in the server and under your own control, can "do whatever you want" and still provide the information in a well formated way (hashtable or whatever) back to the user
  • Yes thats how i assumed it worked, i just can't figure out the correct syntax to add custom operations, i need a base template to work it out from.
  • Caroz, email me at [email protected] .

    Maybe we can pool our knowledge together and figure this thing out as I am trying to make an MMO aswell.
  • Did you check out these:
    http://developer.exitgames.com/blankserversetup/partone
    http://developer.exitgames.com/blankserversetup/parttwo

    This shows how to setup a blank server and while doing so, it shows how to setup a Operation as well.
  • Amaz1ng , Caroz:- you guys working on anything, i too am in the process and would like to bang heads.
Sign In or Register to comment.