Author Topic: Questions about Auto Starting a Server  (Read 6150 times)

masterhyjinx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Questions about Auto Starting a Server
« on: August 06, 2013, 02:01:39 AM »
So what I'm trying to do is set up multiple stations (at least 4) so that the following happens:

  • The first computer to fire up the game and starts it, detects that there is no server (or lobby) and then fires up both
  • The next computer that starts the game will check to see if the server has been started.  Since it has, it joins it and joins the first player in a game
  • The third computer starts the game and after checking, sees that a server has been started but the first game has two players already so it starts a new channel with a new multiplayer game
  • The forth computer starts the game, sees the server and sees player 3 waiting for an opponent so it joins that game.
  • After a game is done, the game will return to the title screen and wait for anyone to "start" the game again in which the process continues pairing up players to play a multiplayer game

This is for a trade show event where we will not be present so it would be optimal if they didn't have to fire up the server themselves and instead the game would do it.  The issues I've been running into so far is that I notice that if I check for a lobby OnStart(), any given client doesn't see the lobby running right away.  I was thinking of putting a timer for each client to wait for the network to initialize before querying the lobby, but I'm nervous about this solution because if the network is busy, I wouldn't know how long to wait.  If I screw it up, two clients start servers which is bad.  I'm sure there is a more elegant solution to this but I don't know what it is quite yet.  This is my first network programming project so I would appreciate any help/advice.


pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #1 on: August 06, 2013, 03:13:23 PM »
I created a scrip that does this.  You just need to have a master server ( the standalone server ) running. then you set the script to query the MS to see if any games are running. If it doesn't find one it will then create one.  You can change how many players can join as well.  Its not a masterpiece but it will do what you are looking for.  If you have any questions about it just ask in the thread and i will do my best to help.

http://www.tasharen.com/forum/index.php?topic=5089.0

masterhyjinx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #2 on: August 06, 2013, 03:31:40 PM »
I created a scrip that does this.  You just need to have a master server ( the standalone server ) running. then you set the script to query the MS to see if any games are running. If it doesn't find one it will then create one.  You can change how many players can join as well.  Its not a masterpiece but it will do what you are looking for.  If you have any questions about it just ask in the thread and i will do my best to help.

http://www.tasharen.com/forum/index.php?topic=5089.0

As I stated above, I am attempting to set it up so that the first client starts the server (Lobby and Game) and use a paradigm where the clients won't accidentally do it themselves after the server has been started.  I cannot assume the people showing the demo even know how to launch a server via terminal so I don't want to rely on that.  I will if I have to but it would be optimal the way I describe in the original post.

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #3 on: August 06, 2013, 04:50:35 PM »
The problem with not having a master server though is that the other machines will not know where to look to see if a server is running or not.  If the machines have static IP's you could have them check each machine to see if a server is running and if no server is found then start one.  Also the way I picture it in my head the first one would take a while before starting the server as it would be trying to connect to 3 machines first and timing out on each before starting the server.  Also would want to add a fall back if 2 machines were started at the same time(You already mentioned this). That could be done by checking for a different server till either it finds a different server or some one else connects to its server.

As far as starting a master server though you can added a batch file to the start up on one of the machines and then you would not have to worry about any one starting a server, it would be done for them.  Also the fall back would be much simpler (already in the script) if 2 clients start at the same time.

Either way though 1 or all 4 machines would need static IP's.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #4 on: August 07, 2013, 04:41:20 AM »
Psycho2day is right. Unless everyone is playing on the same LAN, you need to have a "central meeting place" of some kind.

masterhyjinx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #5 on: August 07, 2013, 10:44:53 PM »
Right.  I never explicitly said that this was going be a LAN situation.  That's my bad.  Thanks for the replies pyscho2day, I need to stop posting at 4 a.m.  4 stations are going to be set up on their own network at a trade show.  I've been working with TNet and it seems the best way is to  just:
  • When the game starts, wait for a small amount of time, say 10 seconds,
  • During that time, wait to see the lobby server reports a server running,
  • If a server shows up, just join it and either set up a new game or join one,
  • If the 10 second timer expires, so no server has been detected, start one up.

I'm still pretty sure that there will be race conditions doing it this way. 

pyscho2day, you are right if this was going to be running over the internet.  Fortunately, we aren't doing that for this demo, ESPECIALLY at a trade show where a reliable internet connection is as rare as a Unicorn.  Thanks.

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #6 on: August 07, 2013, 10:55:41 PM »
That they are, but even in Lan environment your start-up is going to wait a while as you have to wait for the time out and then move to the next one and then wait.  Are you going to set up the machines before they leave for the trade show or are you just going to provide software for some one and they install on the machines and go?

Last Trade show i was at (January of this year) they wanted $250 a day for a 10Mb connection that every one had to share. Eff that, Hooked up to my phone and taped it to the case on the back side that had a box that covered it so the reps couldn't see it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Questions about Auto Starting a Server
« Reply #7 on: August 08, 2013, 08:59:51 AM »
Haha, smart. I'll remember that one for the future :)