Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

server side scripting

Discussion in 'General Discussion' started by Merchant1307, Jan 28, 2018.

  1. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    I'm self taught c# still at a beginner level. I feel like I can code most things I want in the unity client however when it comes to the server side I have no idea where to start.

    I'm willing to take a year or more learning server side scripting to make my small mmo type of game functional how I want it to be however I have no idea where to start learning server side scripting.

    I don't want to use unitys online service since it doesnt seem it would be able to host a world and instances for arenas/dungeons.

    Do I get a cheap vps and then upload my server scripts to them and then what connect my game and it automaticall communicates? This part needs clarification I dont understand how its all put together.

    I can understand php summarized you upload files to a server that runs php and then the server side runs php scripts when you call from the clients browser. The game world I'm a bit newer to and have to learn networking which has always been confusing for me.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    Let me start by saying that networking is not a beginner topic, but there are ways for a beginner to approach networking without being completely overwhelming by it. One of the easiest of these is Unity's HLAPI. It's flexible enough that you can use it to create both normal multiplayer games and small-scale persistent worlds.

    https://unity3d.com/learn/tutorials/s/multiplayer-networking

    With Unity's HLAPI you basically create the scenes the same way you would have created them for a normal multiplayer game but instead of the scenes behind handled by a copy of the game on the player's side you have a master server that handles them. Since HLAPI can only handle a single scene at a time, you need to spawn a copy of the server for each instance you need.

    There is a barebones master server framework on Github.

    https://github.com/alvyxaz/barebones-masterserver/wiki

    Alternatively you can use uMMORPG.

    https://ummorpg.net/
    https://www.assetstore.unity3d.com/en/#!/content/51212

    Yes, unless you want the players themselves to host the game you'll need a server for it. I recommend a cloud computing service where you can start with a low cost tier and then upgrade as needed down the road.

    My personal favorite is DigitalOcean.

    https://www.digitalocean.com/
     
  3. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Whats all uploaded to the vps server for it to work?

    I've looked through unitys hlapi and would use it if it could cover what I wanted but it doesnt seem to be able to (A world list like runescape and instanced pvp like guildwars) and if I start from a game I coded to be an mmo in unity thats already done (its not but say its done) I dont understand what I code on the server to communicate with my game and how.

    The hlapi looked easy enough to get started in but wouldnt be what I want so why start learning an api I dont need? Its like taking java lessons to write csharp.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    There are no answers to this that are not "everything your server needs to function". It's entirely dependent on the game.

    Very few affordable networking solutions are able to handle everything themselves and none of them to my knowledge are designed for persistent worlds (at least nothing approaching the scale of an MMO).

    You need some way to handle player accounts and transferring player data between instances, some way to handle the instances themselves (HLAPI can handle this one), some way to handle communication between players, and so on.

    Building everything yourself is definitely an option but why not at least determine if the existing solutions can do it too?

    My recommendation was solely because you said you were a beginner. While it's commendable to be willing to properly learn networking, you're going to want to become a competent programmer before you try tackling an advanced topic.
     
    Last edited: Jan 29, 2018
    fedecaccia and Kiwasi like this.
  5. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Is there a server copy of the game uploaded to the server or just scripts? Are the server side scripts almost mirrors of the ones in unity like say for combat just similar combat logic in a script on the server the players client communicates with so the server can apply the logic globally?

    I wont really be tackling network head on for a while and I will be pretty good at csharp aside from networking at that time and I would also like to maybe prepare my code for it now while writing it on what I believe is the client side (in unity). I'm beginner now but when I've been seeing something new I've been taking it slow to really understand it and it has helped me learn the language to be able to write and understand most of the stuff to make an mmo on the client side (in unity) but when it comes to a server I dont know what all it would need on the server... My attacks are ready to hit other players but I'm guessing it will have to be edited to send details to the server first when it hits.

    What I choose for networking doesnt have to have qued instances and selectable worlds right away as long as I can script those myself for surely in that networking it would be fine.

    Atavism has some features but is written in java on the server side and I would want my own stuff (combat/etc) written and not have a clone of atavism.
     
    Last edited: Jan 29, 2018
  6. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    @Merchant1307 Generally servers aren't anything to do with the game at all whatsoever.

    Think of a server as the mail man/woman.

    You put a message in your mail box, and the server simply relays that message to the desired persons.
    That's all a server is, it relays your message from A to B,C,D,E,F, etc.

    So with that being said, yes some servers can have some custom logic to them that works ideally with the game you want to make, but they are moreso permissions logic... EXAMPLE

    Player 1 sends a message to server and asks, hey can I pick up this weapon.
    The server then checks if you are allowed (perhaps a database with a permission that you are the right XP or Level).
    Then the server will return to you if you want - a 0 or a 1 (to save bandwidth). 0 being nope you can't, 1 being yes.

    If you can in fact pick up the item, the server will then send to other players via the Mail Box the post office uses, that hey this person got this, it is no longer in this area to pick up.

    Hope that makes sense to you.
     
    Kiwasi and Ryiah like this.
  7. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Also I wouldn't recommend making your game in single player first, other wise you'll just be re-writing the entire game again to make it working for netcode. Just a hint of advice.
     
    Kiwasi and Ryiah like this.
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    For the record what @N1warhead is describing is typically known as a relay server. Unity's paid service is basically just this plus a matchmaking service. For normal multiplayer you don't need much more than this (plus some way to handle account data if you have an IAP store) but for a persistent world you wouldn't take this approach.
     
    Last edited: Jan 29, 2018
  9. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
  10. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    I'm needing guidance on writing my own server side logic that corresponds with my current code (or altered code)/what all is required for a server to function aside from just logic/how it differs from non server coding.
     
  11. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    @Merchant1307 : If you're talking about the way I mentioned in above posts. Then you want to either use Unity LLAPI, or Photon Server, or Forge Networking (Free now), or learn sockets and make your own server (not really recommended for beginners) unless you just want to learn it without any expectation of it being perfect at first.

    There's not really much we can help guide you on at this point though as the topic of the last question is quite broad and depends on many many factors of what you decide to do.

    Neither solution is going to 100% give you what you want right out of the box, well - for an MMO or MOBA it won't.
    All will take some critical logic thinking. Not always does it need to be server side, sometimes you can make things work client-side perfectly fine, keep that in mind.

    If for some reason you have issue with server-side logic and thinking, perhaps try to bend your mind around how to do it without server and use the plenty of cloud networking solutions and just make your game (Unet, photon, etc).
     
  12. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Is learning sockets what I would need to learn to understand what to do to code the server to handle the worldlist and instanced pvp? That sounds like learning how to connect to a server. Would it have me prepared to code my own gaming server?

    None of those solutions will give me what I want out of the box but are they even capable of being modded to suite my needs is the question most dont seem to and some arent in csharp.
     
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    On the topic of the LLAPI...

    http://www.robotmonkeybrain.com/good-enough-guide-to-unitys-unet-transport-layer-llapi/

    Some of them provide source code and are intended to be modified out of the box. The HLAPI is a great example of this because it's literally intended to be a starting point for people wanting to develop their own solution. It just took off as an out of the box solution because it's a solid one.

    https://bitbucket.org/Unity-Technologies/networking

    Some people have been working on extending the functionality too.

    https://forum.unity.com/threads/unet-hlapi-pro-taking-unet-to-the-next-level.425437/

    Other solutions though are closed source. Both the LLAPI and Photon are examples. Having access to the source isn't always that useful either. Photon relies on cloud servers owned by the company developing it while the LLAPI is just a lightweight cross-platform wrapper around platform dependent APIs.
     
    Last edited: Jan 29, 2018
  14. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    what topics should I be studying like sockets to be able to understand server side scripts, understand how to run the game as a world and an instance on the server and the servers themselves to function?
     
  15. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Wouldnt a lot of the server logic be similar to what was already done?

    If we were chopping wood that gave wood in inventory and experience per chop, tree has finite resources what all could be done in client side I know experience is alteast more than likely sent to server for storing in databases.
     
  16. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Depends on the network solution I suppose... I'm mainly used to Photon Server/Cloud..
    For example, photon really isn't much much different. Example below (may not be 10000% accurate) just example.

    Code (CSharp):
    1. // Normal Single Player Code
    2. void Update(){
    3. if(Input.GetMouseButtonDown(0)){
    4. ShootGun();
    5. }
    6. }
    7.  
    8. private void ShootGun(){
    9. //Shoots gun.
    10. }
    11.  
    12. // Multiplayer Code
    13. public PhotonView myView; // << Drag photon view into inspector (Example).
    14. void Update(){
    15. if(Input.GetMouseButtonDown(0)){
    16. myView.RPC("ShootGun",PhotonTargets.Others); //  RPC = Remote Procedural Call. ( Single message to server).
    17. ShootGun();
    18. // << The reason I call it like a normal method here is as you can see above 'Others' would send the shoot command // to other players, saving 1 message sent over network to just call it locally on my end instead.
    19. }
    20. }
    21.  
    22. private void ShootGun(){
    23. //Shoots gun.
    24. }

    However with this being said, in a traditional Dedicated Server setup, you'd go about this entirely different.
    Which would result in A LOT more work involved.

    For example, instead of damaging the tree on your end, lets say you swing your axe.
    First you'd ask the server for permission to swing the axe
    Then if the server says yes, when you hit the tree, you then ask the server for permission to damage it (if it's a damageable tree)
    Then if it says yes it will then tell everybody (including you) that the tree was then hurt.

    EDIT: Keep in mind, this is expressed only from my observation and opinion from my own experience, things could be done differently today with something new I don't know about, or have yet to try.
     
  17. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Dude, scroll way back. It doesn't sound like you are ready for a server yet. Start smaller. Way smaller.

    Get two instances of your game running on one PC. Have them talk to each other. Then move them onto different pcs.

    Once you have a feel for that, you might be ready to tackle client-server architecture. But at the moment you don't even know enough to ask the right questions.
     
    Last edited: Jan 30, 2018
    N1warhead and Martin_H like this.
  18. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    Does a vps act as a poor mans ded server?

    When you swing the axe and ask permission you'd basically use the single player logic on the server so almost mirroring your code if you wrote it out prototyped?
     
  19. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I'm starting to grasp that as well, the only reason I haven't given up yet is because I understand the many questions involved. But granted it's starting to sound more like ' make me server please ' posts lol.

    @Merchant1307 : not necessarily, I mean yeah you can make Unity its self an instance of a server and run all core game-logic on it, but why would you? Quit thinking of the server as 'The Game' on another machine, I mean it can be, but there's a reason most real true servers out there are console applications. And it's not because it's only it looks nicer, but in fact runs sooooo much faster.....

    Send a 1 or 0 to server to save bandwidth, it will check against some custom logic (unrelated to the game) only an (INTERPRETATION) of what it is, and returns a 0 or 1 to you.

    Don't think of the server as the game, only a computer that interprets what you send it into something that makes sense...

    Example:
    Request permission to explode tank
    Server checks if tank exists
    Server tells you it exist by sending you a 1
    You then Request the server to place the charge
    Server sends you a 1 if you have any or 0 if you don't.
    Then you place it.

    Again, don't think of the server as the game, just think of the sever as a bunch of int and strings that have like the US Constitution (Checks and Balances)....

    Checks an int if you have enough C4,
    Tells you 1 if you do, then you place it
    then the server takes 1 from your C4 Integer,etc.

    I can't really help much more than this man, really, I can't.
    Youtube tutorials, read books, just something. Sitting here asking every single thing isn't teaching you anything.
     
  20. Merchant1307

    Merchant1307

    Joined:
    Jan 29, 2016
    Posts:
    33
    I know I'm pretty clueless... It seems as if the server needs game logic or a copy of the game to even know what exists and similar things to check...

    if I never posted id still be in the dark rather than having an idea where to start.
     
    Last edited: Jan 31, 2018