Is it possible for the server to handle the collisions between players/enemies?
Yes, but not wise.
Is it even worth doing or should the client handle his own collisions and notify the server when there is one? (So that the server can dispatch the message to other clients).
Essentially, yes. 'Play' the game on the client and when something happens that affects some other object in the game, notify the server which will then notify it's listening client that has that object.
Any good articles on the topic?
Amazon has several good books about building multi-player games.
[2] Communication is UDP only. There will be one listening socket. Since each instance of a game will probably be a different thread, when I receive socket information, what is the best way to dispatch it to the other threads? I see two solutions:
- Create a buffer for each instance of a game. When the main loop receives info it locks the buffer, puts the information there, and unlocks it. The thread is then notified of available info (thread_cond? Something more elegant?) and locks/copies/erases/unlocks the buffer.
- Create localhost sockets, for each instance of a game. The main loop will get information from the main UDP socket and dispatches it to the new "local" socket that is different for each instance.
Anything I've missed?
Since your server is the one listening and normally (in most servers) constantly listening for new players or connections it should be able to maintain a map of sorts that maps from ip to specific thread or something along those lines. Broadcasting a message is a simple matter of iterating the list/map and calling a function that those IGameThread objects must implement.
IE: One of a million ways to do it
Code:
class IGameThreadListener
{
public:
virtual ~IGameThreadListener() { }
virtual void NotifyThreadEvent(unsigned int event) = 0;
.....
};
class Game : public IGameThreadListener
{
public:
...
virtual void NotifyThreadEvent(unsigned int event);
static void ThreadMain(); //Called by Thread object
private:
Thread *m_pThread; //your custom thread object
};
void Game::NotifyThreadEvent(unsigned int event)
{
//respond to event
}
Obviously I haven't gone through a design meeting or anything to come up with this so I'm sure it has many shortcomings but it is an example of one way to go about doing it.