Author Topic: A few questions.  (Read 4869 times)

MLow

  • Guest
A few questions.
« on: August 20, 2013, 06:08:07 PM »
I'm a bit confused. This system seemed like the perfect shortcut to do my game idea. However delving into the exact ways I would do things bring questions up that I can't seem to work out.

Say I want to have a LAN style game, with pickups that spawn, items and boosts that sort of thing. Who decides to spawn these things? I would like to maintain some control over these things. But at the same time I most certainly want there to be a degree of randomness. I for instance want to make it so if there are any players near the spawn area, no items spawn. So that if an area is empty of players, the spawn areas are free to choose an item randomly from the list, and spawn that item.(be it a boost, health, ammo, weapon)

I'm a bit confused on how to do these things. I don't really want this kind of game logic running on all the clients. So I'm not entirely sure how I would go about setting this kind of thing up, where only the host runs this kind of logic.

MLow

  • Guest
Re: A few questions.
« Reply #1 on: August 20, 2013, 08:42:04 PM »
Gave a read of the text on this page: http://www.tasharen.com/?page_id=4537

The text is NOT a transcript of the video, so that confused me. In essence the video shows setting up with the executable server, the text on the other hand explains how to use a unity built game as the server. So that threw me off a bit. But it looks like everything I want to do is possible, just need to set it up so that the game logic checks if it is the host, if it isn't skip the logic. Simple enough. Seems hackable but I will worry about that later. I just wanted to make sure only the server runs certain logic.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions.
« Reply #2 on: August 21, 2013, 09:44:22 AM »
That's generally how you want it to be, yes. Either check for "is host" or check the "is owner" flag (on the TNObject). An object can only have one owner, and generally the owner is the person who created the object.

MLow

  • Guest
Re: A few questions.
« Reply #3 on: August 21, 2013, 11:34:35 AM »
I'm running into the weird situation now, where, I have started a server instance but am a bit confused with what the status bools are coming up as. For instance when the server instance is started in a build, before I even start the server instance the isHosting flag is true.

I'm just trying to nail down the flags that will be true/false when I am want to check and do logic on the server only. When it is a client. Etc.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions.
« Reply #4 on: August 21, 2013, 01:09:38 PM »
Single player = you're still "hosting" a game. TNManager.isConnected tells you whether you are actually connected. Check TNManager.isXXX series of functions in general.

MLow

  • Guest
Re: A few questions.
« Reply #5 on: August 21, 2013, 01:39:37 PM »
So if your isConnected is false, and isHosting true, you are running single player offline.(in the menu in my case)

If both are true then you are the server? Or does the server need to be in the same channel? Do you join the channel with the server? That didn't seem to work when I tried, it would not give an error or anything it just never joined the channel/load level. So I manually loaded the game level through TNManager.

I'm going off this list: http://www.tasharen.com/?page_id=4523

I kind of feel there is a gap in the text tutorial. I know I'm just a newb and people who know programming can probably easily figure out what needs to be done. But the video tutorial is great for me, I got it working without pausing the video. But the text tutorial is what I'm interested in, an authoritative server that is running the game, to be able to control logic.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions.
« Reply #6 on: August 22, 2013, 09:31:44 AM »
If both isConnected and isHosting are true it simply means you are the "host" of the channel you are in. The server can be hosted remotely. Try not to confuse "host" and "server". Server is what allows players to connect. Host is just another client -- there can only be one "host" per channel. Think: authoritative player.

MLow

  • Guest
Re: A few questions.
« Reply #7 on: August 22, 2013, 08:31:50 PM »
So then can I have a server be a host? It sounds like your making it out that they are separate. When I tried to join a channel as a server, it didn't work but gave no error.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions.
« Reply #8 on: August 22, 2013, 09:31:38 PM »
Think of it as a chat room. To connect to the chat room, there must be a server software. You connect to the chat room using a client -- such as Skype. One person -- usually the first person to join this chat -- is designated to be the operator / moderator / host.

You can't join the chat room from the server, because a server simply lets clients connect. It has no client itself.

To join the server you need a client running. You can have both the server and the client applications running on the same computer though.

MLow

  • Guest
Re: A few questions.
« Reply #9 on: August 22, 2013, 10:11:26 PM »
Hm, ok. So let's say I run the executable server with a batch script that keeps it alive, restarts it if it crashes or closes. Then I have a unity build for the host(same as the client, but has a host flag set) what might be a way to only let the host flag set unity build only be the host. I guess I'm imagining that there might be an issue where when I start the server, a client can somehow connect before the host build and end up as a host instead of a build that I control. If I'm using the executable as the server, I would have to modify the source or something to whitelist the ip or machine.(which I'm not that much of a programmer so I'm concerned I cannot do that)

I guess what I'm getting at with this whole(long winded) thread, is how would you do an authoritative setup. With the host and server always under your control.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions.
« Reply #10 on: August 22, 2013, 11:21:44 PM »
Host flag? Host flag is generally read-only. You're still missing the point. There is nothing special about the "host" status. "Host" simply means another player. Only one player in the channel has the "host" designation. If you are running AI logic in your game, only the host should be doing it, and everyone else should only be receiving the result.

When you build your client, it's just that -- your client. First person to join the channel automatically becomes the "host". When that player leaves, host status is given to another player.

MLow

  • Guest
Re: A few questions.
« Reply #11 on: August 23, 2013, 03:23:38 AM »
Ok I think I'm getting it a little better. Is there any way to control who becomes host, or is that something the server instance controls automatically. I suppose I can look around in the code and see. I'd like to be the only host for this project and control it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions.
« Reply #12 on: August 23, 2013, 10:59:28 AM »
You can transfer the host status, but most of the time it's automatic.