http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: Multiplayer networking advice



I've written a few servers but am not anywhere near an expert on the
subject so I'm sure other people will chime in too but...

>  OnKeyDown (lets say to the left)
>  Client#1's character moves left
>  OnKeyUp
>  Client#1 sends his position to the SERVER

When you are making any server/client software, for perfect security
you always have to assume the client is lying about everything :P

Cause basically in the above setup, if i rigged my client to send you
whatever coordinates i wanted, i would basically have a teleport hack
that i could use to teleport around where ever I want.

Some people were talking about this in another thread but what you
might want to do is something more like this (although i know this is
also kind of ameteur hehe):
1) player presses key to walk left, client tells server "begin walking left".
2) client moves player on screen while the player walks.
3) when player releases key, client tells server "stop walking left".
4) while this whole thing was happening, the server was periodically
broadcasting information to all players about the players that had
been moving - sending ALSO to the client who was moving.

The reason you also send it to the player who was moving is because if
they have a lot of lag, their position on the server might not match
their position on the client, so that is a way of teleporting the
player back to the right position client side whenever needed.

For chatting, that sounds reasonable, if you know the difference
between UDP and TCP/IP, you could probably even use UDP w/o much
checking for chatting which may get you some increased preformance (:

>  IF O.K. LOG THE IP ADDRESS (I guess keep it in memory or write it to a file... I'm not terrible sure)

Would this be for security reasons, to know what IP's have logged in
for each account?  If you know how to use a database (or feel like you
want to try!) that may be a good place to log the ip address info
since it handles the storage in memory / to files issue for you.  You
could also store login information and even maybe player data in the
database tables, which would give you a neat interface to be able to
quickly update or search through your data.

Databases are pretty cool, but it might be a steep learning curve to
get one working, and they aren't always as efficient as just setting
up your own flat file system so up to you if you think that'd be a
good idea

TCP/IP vs UDP

If you don't know the difference between TCP/IP and UDP, TCP/IP is
reliable transmisions while UDP is not necesarily reliable, but is a
lot faster with less overhead.  If you have things in your game that
if the information doesn't get to the player on a rare basis you'd be
ok with it, you might want to check out using UDP for those thing, and
using TCP/IP for the things that really really matter.  You can
squeeze a lot more network preformance out of your game that way.

Multithreaded server

If you haven't ever done anything with threads you may want to for the
server.  A model that web servers etc use that I've also used for
games with pretty decent success is this...

 Have 1 main thread that is in a loop like this:

while(GameRunning)
{
    while(NewConnections())
        AcceptNewConnectionAndSpawnNewThreadsForIt();

    sleep(500);
}

what that does is accept any new connections that may be waiting to
connect to the server, then sleep for 500 miliseconds.  You want the
server to sleep in this loop so your computer isn't spending it's time
constantly searching for new connections and using up all the CPU on
that.

Each connection should have it's own thread that watches for input
from the player and does logic and communicates with the main worker
thread of the game.

When a player disconnects or is booted, you can shut down the thread,
but having a seperate "worker thread" for each connection seems to be
a pretty reasonable design at least as far as I've seen.

Hope this helps, and if I've misled you I'm sure other more
knowledgable people will speak up :P

But don't forget! Never trust the client to keep track of things which
they could be lying about (how much life they have, where they are
located, what level they are etc) cause then you will always have a
way for someone to hack your game! (:


On Jan 27, 2008 4:07 PM, Taylor Peterson <assbone@gmail.com> wrote:
> Not yet, I'm still working on it.  I've never coded a server before so I've
> been writing stuff down and pondering it.  Any clues on how to handle
> multiple connected people would be helpful though as I've been stuck on how
> to do that.  (._.)
>
> I was think of having the server log the IP addresses that connect and
> sending them data each update.
>
> For instance:
> CLIENT CONNECTS
> SERVER GETS THE IP ADDRESSES AND CONFIG STUFF
> SERVER CHECKS THE USERNAME AND PASS
> IF O.K. LOG THE IP ADDRESS (I guess keep it in memory or write it to a
> file... I'm not terrible sure)
> SEND THE DATA ARRAYS TO THE CLIENT
> SEND DATA TO THE OTHER CLIENTS
> BLAH BLAH BLAH
>
> Am I on the right track?
>
> Also, for moving and stuff like that I've come up with this:
> + = client
> [] = server
>
> OnKeyDown (lets say to the left)
> Client#1's character moves left
> OnKeyUp
> Client#1 sends his position to the SERVER
> + -------> []
> And SERVER sends his position to Client#2,3,ect and the screen updates
> + <------- [] -------> +
>
> Same thing would go for chating...
> Client#1 sends data to the server and the server sends it to the other
> clients.
>
> Is that an efficient way to handle it?
>
> Thanks a lot for your help,
> Taylor
>
>
>
> On Jan 27, 2008 3:56 PM, Alan Wolfe <alan.wolfe@gmail.com> wrote:
> >
> >
> >
> > Seems like a decent way to go about it (:
> >
> > One thing I would suggest is having each image URL have a unique ID so
> > that when you use wget or whatever to grab the images from their URL,
> > you don't have to deal with naming conflicts, you just name them based
> > on their unique ID#.
> >
> > IE instead of you and I both having an "avatar.jpg" on our urls making
> > a naming conflict, my URL is ID #3 and yours is #5 so it'd just be
> > 3.jpg and 5.jpg on the client computer.
> >
> > Your client stuff sounds pretty decent IMO, do you have the server
> > stuff figured out yet too?
> >
> >
> >
> >
> > On Jan 27, 2008 11:35 AM, Taylor Peterson <assbone@gmail.com> wrote:
> > > Hello everyone~
> > >
> > > I'm not a very frequent poster, but I do read a lot.  I was looking for
> some
> > > advice on networking a game as I'm very new in that area.
> > > In my little network game players will be able to make their own little
> > > avatars (in what ever image editing program) and upload them somewhere
> (like
> > > imageshack or photobucket)  and paste the url to those images into a
> config
> > > file.  And they'll be able to interact with others and what not in a
> little
> > > world.
> > >
> > > My problem with this is, I've never done a game where more than two
> people
> > > connected to each other and play (they'll have to connect to a server
> now).
> > > So I'm confused as to how I could draw all of them on screen and keep it
> > > updated.
> > >
> > > Here's what I've come up with in my own inexperienced mind:
> > > http://commabunny.org/THE/networking_shiz
> > >
> > > Please critique it, or tell me if it's even posible.
> > >
> > > Thanks,
> > > Taylor
> > >
> >
> > ---------------------
> > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> >
> >
> >
>
>
>
> --
> -Taylor Peterson

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html