Game Development Reference
In-Depth Information
'
There
s really only one method, AttachRemotePlayer() , which is called by the
game logic when new remote views are added. This is where the NetMsg_Player-
LoginOk message is generated by the server, which contains the unique socket ID
number down to the client so all the players of a multiplayer game don
'
t get
confused.
void NetworkGameView::AttachRemotePlayer(int sockID)
{
m_SockId = sockID;
std::ostrstream out;
out << static_cast<int>(RemoteEventSocket::NetMsg_PlayerLoginOk) << ““;
out << m_SockId << “”;
out << m_ActorId << “”;
out << “\r\n”;
shared_ptr<BinaryPacket> gvidMsg(GCC_NEW BinaryPacket(out.rdbuf()->str(),
(u_long)out.pcount()));
g_pSocketManager->Send(m_SockId, gvidMsg);
}
Gosh, if It's That Easy
There is much more to network programming than I
ve had the pages to teach you
here. First, remote games need to be very smart about handling slow Internet connec-
tivity by predicting moves and handing things elegantly when those predictions are
wrong. For enterprise games like World of Warcraft, you have to take the simple
architecture in this topic and extend it into a hierarchy of server computers. You
also have to create technology that prevents cheating and hacking. These tasks
could, and do, fill volumes on the subject.
Still, I hope you feel that what you
'
ve seen in this chapter is an excellent start. Cer-
tainly, if you want to learn network programming without starting from scratch, the
code in this chapter and on the topic ' s website will give you something you can play
with. You can experiment with it, break it, and put it back in good order. That
'
'
s the
best way to learn.
That is, of course, how I started, only I believe the little record player I ruined when I
was a kid never did work again. Sorry, Mom!
 
 
Search WWH ::




Custom Search