Search Unity

Omuni Online networking

Discussion in 'Multiplayer' started by diedy, Sep 29, 2010.

  1. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    Hello unity community !

    My name is Diede and I recently joined Moya games, working on Omuni Online.
    I made a database and login scripts and now I want to make the networking.
    I try'd out smartfox server, but when I tested it it was very lagy, even with only 2 players.
    Smartfox is also easy to use, too easy cause I can't make any huge but simple changes.
    Unity's networking looks ok for me, I've downloaded and installed unity3 pro and I would like to do next:
    note that I don't know how other games do this and I'm here to ask that as well as whether I'm gonna do it the correct way.

    Client can register and than login using WWW -> php -> mysql database.
    If logged in successfully it loads the Omuni level and saves your login name.
    In the Omuni level it should connect to the networking server, when successfully connected the client sends hes name to the server and the server than gets hes data from the server and than RPC calls a new object with name Remote[playerName] , all clients get to see this new player and hes name with GUI text above him.
    Than the client that wanted to spawn creates a localPlayer when he gets the call with hes name. the local player has a camera following the localPlayer and a walking script. Like this, the position of the player is calculated in the server. If the player presses W to move forward he sends a message to the server that he wants to move, the server than moves the Remote[playerName] forward, when the W button is up the clients sends that he is not moving forward anymore, to make the client see hes character walk without lag I must make that the server sends the position of hes player only when he stops moving, and that the localPlayer moves forward with the same speed. This way speed hackers get teleported back to the real speed position when they stop moving. I also see other players lag a little bit, is it possible make the server send other peoples position over UDP for less lag ?
    Than I should make that when a client leaves the server saves hes position and other vars and than delete hes object.

    Is this the right way to make a MMORPG ? please clear things up for me.
    Thanks in advance !
     
  2. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    The team I'm working with is also aiming for a MMO, but we are taking a different approach. I also started off with smartfox, and didn't like its restrictions. We are now using beamserver 2 I decided to try an approach that is not so much focused on sending every action to and from the server, and more on just getting a working framework fast. Here is my approach: There will be 2 kinds of gameobjects, static and dynamic. The static objects will be things like trees, rocks, terrain, buildings, ect. The server does not even need to know about these objects since they are the same for every client and don't really need any scripts attached to them. The other dynamic objects are things like characters, enemies, projectiles, NPCs, mounts, ect. these are objects that change position and are modified as the game is played. They will have a script attached that updates their transform. This script would send a message to the server with the transform info, and also the object name. The server would verify the request by looking though a mysql database to make sure the requested object exists, and then register it in another database as "being in the gameworld." The server would then broadcast to all the clients the info about the object, and the clients would create the object. The transform update script would be run every 0.01 second or so to keep the clients updated. The same method would be used for animations. This way, a lot of the scripting could be optimized. For example, you could just use the 3rd person script in the demo for walking, as the transform/animation scripts would take care of everything else. Of course for attacks you would want validate it against the server. This may not give that much security, but for me, getting a working game out is more important than security right now. For the login I'm just going to import some mysql libraries into the C# server project and validate the login stuff. I would not recommend unity for the back-end networking because its not optimized for MMOs. Well, thats my 2 cents. Hope you found this helpful.
     
  3. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    Thanks for your reply, I try'd out beamserver2 and I like it alot.
    The only problem I have is connecting to the server, right now it's just on localhost.
    I wrote a server and a Unity3 client with the docs but I can't seem to connect.
    I downloaded their sources but they didn't work either.
    Only for the chat one, that one made a connection but the client doesn't react on that.
    Did you try this ? do you mind sharing your codes with me ?
    Thanks in advance !
     
  4. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    You need the policy server setup.
     
  5. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    Can you give an explenation for that ? thanks !
     
  6. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
  7. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
  8. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    You have to run the policy server that comes with unity 3 for any kind of networking to work. That link that appels gave has all the info you need.
     
  9. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    But that's for the web player ? I just use it inside unity3 ?
    And where do I have to type what to fix this ?
     
  10. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    change your build settings to standalone, then it should work in the editor.
     
  11. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    It is build as a stand alone.. to test it I've put Security.PrefetchSocketPolicy("127.0.0.1", 10000); into void start.. doesn't work.
    A friend of my'n downloaded the files from the tutorials and it worked directly in unity 2.6... I wanted to uninstall unity3 and install unity3 but I cant find a download :( what should I do ? I'm never gonna put this in a web player. tosha, can you please give some explenation indstead of reditecting me ? thanks !
     
  12. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    Yeah well it works directly in the editor in 2.6. If you want to test it in unity 3, just build the project, as a webplayer or a standalone it does not matter, and run the .exe file that comes with unity to start the socket policy server. You only need to prefetch the socket policy if you are hosting the socket policy server on a port other than 843, and on a ip other than the local one. For some reason you can't test from inside the editor. This really sucks, and I think the unity team should look into it. Thats all you need for a testing quick fix. As for sharing code, I don't really have any yet. What I posted is just my blueprint, I have yet to make the house. ;) I would send you unity 2.6 (I saved a copy) but I assume your on a pc and I'm on a mac.
     
  13. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    I just tested it with beamserver and no policy server or policy file and it works fine in the editor.
     
  14. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    Looks like I'm having problems with setting up a local server :(
     
  15. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    I have a server compiled in visual basic with the BeamServer2 library's.
    My client is written in unity and connects to 127.0.0.1 on port 10000. My files are the same as the files from the docs/tutorials from BeamServer2.
    This connection works in unity2.6(Not sure if it works on my PC tho..)
    But the connection doesn't work on my PC with unity3, reason seems to be that policy stuff.
    So I have put a crossdomain.xml into the same folder as my compiled client.exe (from unity)
    and into the same folder as my server.exe made in visualbasic.
    the crossdomain.xml contains:

    <?xml version="1.0" ?>
    <cross-domain-policy>
    <allow-access-from domain="*" to-ports="*"/>
    </cross-domain-policy>

    When I startup the server and I startup the client, the client does nothing(so he cant connect.)
    Security.PrefetchSocketPolicy("127.0.0.1",10000);
    That happens when this above line is in a cs script at void start.

    I don't know if I need this line but if I take it away the client says connected but the server doesn't print a connection.
    If I close the server and than run the client the client also says connected.

    I hope somone can explain this :(
     
  16. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    You don't need a crossdomain.xml if your just running locally. Go to your unity install directory. Find the tools folder, inside that there will be a folder called socketpolicyserver or something to that effect. Run the .exe with the --all parameter. (Don't know how to do this on windows I'm on a mac.) Build the project. Run the server. Run the project, not in the editor, but from what you built. You don't need any xml file or any socket prefetch code on the client. It should work now. It just sucks it does not work from editor, the unity team really needs to fix this.

    @appels, are you on a mac? That might have a effect on the project, because mine only works once I build it.

    EDIT: I just tested the webplayer build WITHOUT any policy server running and it worked fine, I just had to build it first. I think the reason its doing this is because its running on local loopback and the policy server is not needed for that. Still weird that I have to build it first to run it though.
     
    Last edited: Oct 1, 2010
  17. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    nope, vista.
     
  18. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    maybe there have been some changes because it didn't work for me when i had webplayer as build settings and now it does.
     
  19. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    maybe that has a effect on the networking aspect of the editor. It seems like mac unity should work better than windows unity because it was made for mac first :p
     
  20. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    Ok, I run the tool with the -- all paramter, I build the client start the server and launch the client, doesn't work... can you help over team vieuwer or something like msn, skype ?
     
  21. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    Ohh I forgot the other thing I changed!! Change the connecting port on the server/client to 4500, the policy server cant handle 10000, its too big.
     
  22. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    It works ! thank you soooooo much !
    I also had to take away Security.PrefetchSocketPolicy("127.0.0.1", 4500);
    Thanks again !
     
  23. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    What do I have to do if I want to build a .exe standalone for a friend to connected over the internet ? what has to be in the .xml ? where do I need to put the .xlm ? and other stuff like that that I might do ?
     
  24. diedy

    diedy

    Joined:
    Sep 29, 2010
    Posts:
    13
    when I host the server and forward my port and I check it with watismijnip.be it says that the port is not open :(
    How come ?
     
  25. tosha96

    tosha96

    Joined:
    Aug 29, 2010
    Posts:
    75
    Well for standalone you don't need a policy server. But don't ask me about port forwarding. I've had a lot of trouble with it in the past, and theres no way to help you without your exact networking setup. This website might help though: http://portforward.com/