Developer guide for multiplayer game

609 33 0
Developer guide for multiplayer game

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Developer’s Guide to Multiplayer Games Andrew Mulholland and Teijo Hakala Wordware Publishing, Inc Library of Congress Cataloging-in-Publication Data Mulholland, Andrew Developer’s guide to multiplayer games / by Andrew Mulholland and Teijo Hakala p cm ISBN 1-55622-868-6 (pbk.) Computer games Programming I Hakala, Teijo II Title QA76.76.C672 M85 795.8'15 dc21 2001 2001046789 CIP © 2002, Wordware Publishing, Inc All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc Printed in the United States of America ISBN 1-55622-868-6 10 0109 OpenGL is a registered trademark of Silicon Graphics, Inc Windows is a registered trademark of Microsoft Corporation Other product names mentioned are used for identification purposes only and may be trademarks of their respective companies All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the above address Telephone inquiries may be made by calling: (972) 423-0090 Contents Theory Introduction Chapter Creating Windows Applications in Visual Studio Introduction Windows Messaging System Creating a Window Sending Information to Your Window Introduction to Static Link Libraries Creating a Static Link Library 10 Using a Static Link Library 13 Final Notes 14 Chapter Internet-Based Database Systems Introduction Installing MySQL Linux Specific Windows Specific Overview of MySQL Creating a Database in MySQL Adding Tables to a Database Adding Data to Tables Viewing Data in a Table Adding Extra Fields to Tables Updating Data in a Field Ordering Output Retrieving the Last Data Entered Limiting Output Data Deleting Data from a Table Deleting Tables and Databases Relational Databases Creating Our Relational Database Player Data Payment Info Notes Rel Friends Rel Enemies Adding Relational Data Manipulating the Friend and Enemy Relational Tables 15 15 16 16 17 18 18 19 22 24 28 30 36 38 40 40 43 46 47 48 50 52 53 55 57 70 iii Contents Other Methods of Data Input Text File Input Native Database Input Backup and Restoration of Databases Backup Restoration MySQL C++ Interface Example — Connecting and Retrieving Data from MySQL Example — Updating Data in MySQL from an Application Summary 73 73 75 77 77 81 83 84 87 90 Chapter Communicating with the Internet 91 Introduction 91 Getting Started 91 Debugging Perl 93 More Text Output Routines 94 Using Files and Templates 96 Reading in a Text File 96 Writing to a Text File 98 Using Templates 99 Using Forms 103 Command Processing 110 Retrieving the Date and Time 118 Installing the Perl Database Interface (DBI) 120 Connecting and Disconnecting 121 Retrieving and Displaying Data 123 Adding New Data 129 Using the Unique ID Field 137 DisplayData Function 147 AddData Function 150 DoAddData Function 151 Modify Function 152 DoModifyData Function 156 DeleteData Function 158 Adding a Search Facility 163 Summary 180 Chapter Introduction to TCP/IP Introduction What is a Protocol? OSI Model OSI Model Layers Internet Protocol Introduction to the Transport Layer Transmission Control Protocol User Datagram Protocol Ports iv 181 181 181 182 183 184 186 186 187 187 Contents Introduction to Sockets Socket Types Address Platforms History of WinSock Choosing the Platform Summary 188 189 189 190 190 191 191 Chapter Basic Sockets Programming Introduction WinSock Initialization WSAStartup Function (Win32) WSACleanup Function (Win32) WSAEnumProtocols Function (Win32) WinSock Initialization Function Error Handling WSAGetLastError Function (Win32) Sockets Data Types Platform Specific Data Types Address Structures IPv4 Address Structure IPv6 Address Structure Generic Address Structure Basic Sockets Functions Socket Function (Unix, Win32) Bind Function (Unix, Win32) Connect Function (Unix, Win32) Listen Function (Unix, Win32) Accept Function (Unix, Win32) Close Function (Unix)/Closesocket Function (Win32) Input/Output Functions Send Function (Unix, Win32) Recv Function (Unix, Win32) Sendto Function (Unix, Win32) Recvfrom Function (Unix, Win32) Address Data Conversion Functions Inet_aton Function (Unix, Win32) Client/Server Programming Server Methods Clients Byte Ordering Creating a Server TCP UDP Simple Echo TCP Server Main Function InitSockets Function 193 193 193 193 194 195 195 198 198 199 199 199 199 200 201 202 202 203 204 205 206 207 207 207 209 210 211 212 212 212 212 214 214 215 216 217 218 221 222 v Contents ServerProcess Function Simple Echo UDP Server InitSockets Function ServerProcess Function Creating a Client TCP UDP Simple Echo TCP Client Main Function InitSockets Function ClientProcess Function Simple Echo UDP Client InitSockets Function ClientProcess Function Running the Simple Echo Application Summary vi 224 225 228 228 230 230 230 231 233 234 235 237 239 239 240 241 Chapter I/O Operations Introduction Detecting Network Events Select Function (Unix, Win32) Macros WSAAsyncSelect Function (Win32) WSAEventSelect Function (Win32) WSAWaitForMultipleEvents Function (Win32) Event Object Multithreading What is Multithreading? CreateThread Function (Win32) Pthread_Create Function (Unix) I/O Strategy Blocking I/O Non-blocking I/O Signal-Driven I/O Multiplexing I/O I/O Control Ioctl (Unix)/IoctlSocket Function (Win32) SetSockOpt/GetSockOpt Function (Unix, Win32) Shutdown Function (Unix, Win32) Broadcasting Searching for Servers Broadcast Function Summary 243 243 243 243 244 245 245 246 247 247 248 248 249 250 250 250 251 252 252 252 253 255 256 256 256 258 Contents Tutorial Introduction 259 Tutorial Using Our 2D Library Introduction Configuring Visual Studio Creating a Skeleton Project Creating the Workspace Adding the Static Libraries Adding the Source File Creating a Basic Windowed Application with 2DLib The WinMain Function The Windows Procedure The Complete Code Using the 2DLib Graphics Routines Graphical Functions 2D Positions on the Screen Use of Colors Plotting a Single Pixel Drawing a Line Drawing a Rectangle/Filled Rectangle Drawing a Triangle/Filled Triangle Graphic Loading Functions Graphics Display (Blitting) Function Keyboard Input Method 2DLib Example — Moving Primitives with the Cursor Keys Complete Code Listing for Example 2DLib Example — Loading and Rotating Graphics Complete Code Listing for Example Summary 261 261 261 262 262 263 263 264 264 266 268 270 270 270 271 271 271 271 272 272 273 273 275 277 280 281 283 Tutorial Creating Your Network Library Introduction Why Create a Network Library of Our Own? Planning the Structure Planning the Functionality Identifying Hosts Sending Data to Hosts Building the Library Windows Unix/Linux Creating Independent Code Creating Definitions for Data Types Protocol Independence Transport Protocol Independence Internet Protocol Independence Log System Getting Started 285 285 285 286 287 287 287 288 288 289 290 290 291 291 292 292 294 vii Contents Setting Up Source and Header Files NET_Socket Class Individual Setup Functions Dependence NET_Socket Class Initialization Functions Constructor Destructor Shutdown Closing Connections Closing Input Event Handle Setting the Local Host Offline Setting Blocking/Non-Blocking Message System Sending/Receiving Data Read Function ReadFrom Function Write Function WriteTo Function WriteAll Function Host ID System Finding Next Free Host Index Giving Local ID Creating the Server CreateServer Function CreateWinServer Function CreateTCPServer Function CreateWinTCPServer Function Accepting a Connection Connecting to the Server ConnectToServer Function CloseConnection Function Multithreading Handling Network Events WinHandleEvents Function ProcessMessages Function Message Recording Complete Independent Version NET_Socket Class Constructor/Destructor RemoteHost Class Initializing/Uninitializing Blocking/Non-blocking I/O Sending/Receiving Data Read Function ReadFrom Function Write Function WriteTo Function viii 294 295 298 301 301 301 301 302 302 303 303 303 304 306 306 309 311 313 315 318 318 319 320 320 321 324 324 325 329 329 336 340 344 345 347 351 351 352 353 354 355 355 356 356 358 359 361 Contents WriteAll Function Message Buffer System Message Buffer Class ReadToBuffer Function ProcessMessageBuffer Function ProcessMessages Function Buffered Function Calls WinHandleEvents Function (Win32) Platform-Dependent Functions NET_WinIOThreadFunc (Win32) NET_WinUDPServerIOThreadFunc (Win32) NET_UnixIOThreadFunc (Unix) NET_UnixUDPServerIOThreadFunc (Unix) Give Local ID Number GiveLocalIdTCP Function GiveLocalIdUDP Function Creating a Server CreateServer Function CreateWinServer Function CreateUnixServer Function CreateTCPServer and CreateUDPServer Functions CreateWinTCPServer Function CreateUnixTCPServer Function NET_UnixPollAcceptFunc Function CreateWinUDPServer Function CreateUnixUDPServer Function AcceptConnection Function Connecting to a Server ConnectToServer Function CloseConnection Function Shutdown Function Final Thoughts Summary Tutorial Creating the Login System Introduction Creating the Database Creating Our Basic Client Application Integrating the Login System (Part 1) Creating Our Dialogs Coding the Login System Creating the Login Server Messages LobbyLogin Message LobbyLoginFeedback Message LobbyCreateAccount Message LobbyCreateAccountFeedback Message 362 364 365 365 366 370 372 372 373 373 375 383 386 390 390 391 394 394 395 398 399 400 400 401 402 403 404 406 406 413 416 416 417 419 419 419 421 429 429 433 438 439 439 440 440 441 ix 580 Appendix B / NetLib.h #ifdef WIN32 int addrLen; #else socklen_t addrLen; #endif // socket address length // socket address length bool online; bool thread; bool NonBlocking; // host online flag // thread running flag // non-blocking flag int messageCounter; int bufsize; // message buffer counter // the length of the next message int lastMessageTime; // seconds from last message int InMessages; // Input buffer messages MessageBuffer_t *InMessageBuffer; #ifdef WIN32 HANDLE SocketInputEvent; #endif void RecordMessage(void); }; class NET_Socket { private: int GiveLocalIdTCP(void); void FindNextFreeHostIndex(void); // Server creation helper functions int CreateUnixTCPServer(SOCKET listenSock); int CreateWinTCPServer(SOCKET listenSock); int CreateUnixUDPServer(SOCKET sock); int CreateWinUDPServer(SOCKET sock); int CreateTCPServer(SOCKET sock); int CreateUDPServer(SOCKET sock); int CreateUnixServer(int port, int Protocol); int CreateWinServer(int port, int Protocol); #ifdef WIN32 int WinHandleEvents(int id, LPWSANETWORKEVENTS NetworkEvents); #endif HOSTID NextFreeHostIndex; Appendix B / NetLib.h 581 public: NET_Socket(); ~NET_Socket(); // Uninitialization functions void CloseConnection(int id, int active); void Shutdown(void); // Miscellanous functions int SetNonBlocking(int id, u_long setBlocking); int GiveLocalIdUDP(sockaddr_in clientAddr); void AcceptConnection(void); int CreateServer(int port, int Protocol); int ConnectToServer(char *ipAddressString, int port, int Protocol); // Data reading / writing functions int ReadToBuffer(HOSTID id, size_t count, bool NonBlocking); int Read(int id, char *buf, size_t count); int Write(int id, char *buf, size_t count); void WriteAll(char *buf, size_t count); int ReadFrom(SOCKET sock, char *buf, size_t count, struct sockaddr *sockAddr, socklen_t *sockLen, bool NonBlocking); int WriteTo(SOCKET sock, char *buf, size_t count, struct sockaddr *sockAddr, socklen_t sockLen); HOSTID GetNextFreeHostIndex(void) { return NextFreeHostIndex; } // Message processing functions void ProcessMessageBuffer(int id); void ProcessMessages(int id); int HandleSocketInputEvent(int id); int HandleSocketOutputEvent(int id); #ifdef WIN32 HANDLE SocketOutputEvent; #endif // Miscellanous variables SOCKET listenSocket; // Listening socket int localId; bool Online; // Local host id // Local online flag 582 Appendix B / NetLib.h int RemoteHosts; RemoteHost_t *RemoteHost; // Amount of remote hosts int Port; // Port in use }; // Thread parameter structure typedef struct { int id; NET_Socket *netParamSocket; } threadParam_t; // host id // NET_Socket pointer // Platform dependent function prototypes #ifdef WIN32 void NET_WinIOThreadFunc(void *ParamPtr); void NET_WinUDPServerIOThreadFunc(void *ParamPtr); #else void *NET_UnixIOThreadFunc(void *ParamPtr); void *NET_UnixUDPServerIOThreadFunc(void *ParamPtr); #endif // Common function prototypes void StartLog(void); void LogString(char *string, ); int NET_Initialize(void); int NET_InitializeWinSock(void); void NET_Shutdown(void); // External functions and variables #ifdef WIN32 extern HWND hWnd_netLib; #endif extern void NET_HandleMessages(NETMSG_GENERIC *Msg); #endif Index * indicates reference contains code listing 2D library, adding to workspace, 263 creating basic windowed application with, 264-270* graphical functions, 270-275 2D library examples loading graphics, 280-283* moving primitives, 275-280* 2D positions, displaying, 270-271 A Accept function, 206 AcceptConnection function, 325-326*, 404-406* Add command, 28 AddData function, 150 AddGame function, 528* address classes, 185 address conversion, 212 functions, 212 address structures, generic, 201 IPv4, 199-200 IPv6, 200 Alter Table command, 28-29 application, 183 creating, 264-270* ApplicationProc function, 540-541* B backing up databases, 77 backup file, 78-80 big-endian order, 214 Bind function, 203-204 blocking function, 303-304 blocking I/O, 250 setting, 355-356 blocking socket, 223 Broadcast function, 256-258* broadcasting, 256 byte ordering, 214 conversion functions, 575-576 C cgi-lib, 91-92 ClientDlgProc, 7-8 ClientProcess function (TCP), 235-237 (UDP), 239-240 clients, 214 creating, 230 handling messages on, 532-535* removing player from, 506 Close function, 207 CloseConnection function, 336-340*, 413-416* Closesocket function, 207 code, creating modular, 110-117* creating platform-independent, 290-291 creating protocol-independent, 291 colors, specifying, 271 command system, 110-118* concurrent server, 190, 213 confirmation message, 305* Connect function, 204 connection, accepting, 325-329* closing, 413-416* ConnectToServer function, 329-336*, 406-413* converting addresses, 212 Create Database command, 18, 47 Create Table command, 20, 48 CreateGame function, 507* CreateGameDialogProc function, 507-508* CreateServer function, 320-321*, 394-395* CreateTCPServer function, 324*, 399* CreateThread function, 248-249 CreateUDPServer function, 399* CreateUnixServer function, 398-399* CreateUnixTCPServer function, 400-401* CreateUnixUDPServer function, 403-404* CreateViewPlayers function, 510* CreateViewPlayersDialogProc function, 511* CreateWinServer function, 321-324*, 395-397* CreateWinTCPServer function, 324-325*, 400* 583 Index CreateWinUDPServer function, 402-403* D daemon_init function, 573-574* data, adding to relational database, 57-70 adding to tables, 22-24 adding with forms, 129-136* deleting from table, 40-43 displaying, 125-129* entering, 73-77 limiting, 40 retrieving, 84-87*, 125-129* retrieving latest, 38-39 sending, 287 sorting, 36-37 updating, 87-90* updating in a field, 30-36 viewing in a table, 24-28 data input, 73-77 data link layer, 183 data structures, 544-545 data types, and platforms, 199 creating definitions for, 290-291 Database Interface module, see DBI databases, adding tables to, 19-22 backing up, 77 connecting to, 84-87* creating in MySQL, 18-46 creating relational, 47-56 deleting, 44-46 manipulating tables in relational, 70-73 relational, 46 restoring, 81-83 structure of relational, 46-47 datagram socket, 189 Datasize message, 305-306* date, retrieving, 118-119* date and time, setting manually, 32-33 setting with MySQL, 31 DBI, 120 adding MySQL support to, 120-121 installing, 120 debug version, 12 debugging Perl script, 93-94 Delete From command, 40-43 584 DeleteData function, 158-163 Describe command, 21, 29, 49 DestroyGame function, 528* dialog, creating, 6-7* DialogBox function, DisplayData function, 147-150 displaying images, 273 DoAddData function, 151-152 DoCreateGame function, 510* DoDestroyGame function, 511-512* DoJoinGame function, 513* DoLogoff function, 514* DoModifyData function, 156-157 DoStartGame function, 542-543* Drop Database command, 44-45 Drop Table command, 43 E echo application, running, 240-241 echo TCP client, creating, 231-233* echo TCP server, creating, 218-221* echo UDP client, creating, 237-239* echo UDP server, creating, 225-228* ENGINE_AddBullet function, 571-572* ENGINE_AddPlayer function, 551* ENGINE_CheckBulletCollisions function, 566-567* ENGINE_CheckFlagCollisions function, 567-569* ENGINE_DrawMap function, 553-555* ENGINE_GenerateRandomMap function, 550* ENGINE_Init function, 545-550* ENGINE_ProcessInput function, 555-561* ENGINE_Render function, 542*, 552* ENGINE_Shutdown function, 551-552* ENGINE_UpdateBullets function, 565-566* ENGINE_UpdatePlayers function, 561-565* ephemeral ports, 188 error handling, 198 event objects, 247 events, detecting network, 243 handling network, 344-350 Excel, using to enter data, 75-77 F fields, adding to tables, 28-30 updating data in, 30-36 Index using unique ID, 137-147* file, reading, 96-98* writing, 98-99* file permissions in Linux, 92 FindNextFreeHostIndex function, 318* footer file, displaying, 101* forms, adding search capability to, 163-180* using, 103-110* using to add data, 129-136* G game engine, 543 game tutorial client application code listing, 472-483* coding game lobby, 498-504* creating chat system, 495-496 creating client application, 421-429* creating database, 419-421 creating dialogs, 429-433 creating game, 527-530 creating game world, 545-552 creating header file for server, 441-442* creating lobby client application, 487-515 creating lobby dialogs, 488-493 creating lobby server application, 516-536 creating login server, 429, 438-439 creating new game, 507-512 creating server file, 442-453* declaring messages, 439-441* executing login system, 483-486 handling chat, 497 handling login messages, 518-519* handling logout messages, 519-520* handling messages, 497, 540-541*, 569-571* handling host, 535-536 identifying players, 497 implementing code in login system, 433-438* integrating login system, 462-472* joining game, 512-514, 530 logging in to game, 498 logging off game, 530-531* server application code listing, 453-461* receiving start game message, 538-539* starting game, 538 storing data, 544-545 synchronizing players, 543-544 updating game screen, 542-543 updating game world, 552-569 updating lobby lists, 514-515 updating players, 506 game tutorial code login.cpp, 475-480* login.h, 475* main.cpp, 426-428*, 472-475* main.h, 472* netcommon.h, 453-455* network.cpp, 480-483* network.h, 480 server.cpp, 442*, 455-461* server.h, 441-442*, 455* Get method, 108 GetSockOpt function, 253-255 GFX_Blit function, 273 GFX_Line function, 271 GFX_LoadBitmap function, 272 GFX_Pixel function, 271 GFX_Rect function, 271-272 GFX_RectFill function, 271-272 GFX_Tri function, 272 GFX_TriFill function, 272 GiveLocalIdTCP function, 319-320*, 390* GiveLocalIdUPD function, 391-394* graphics, loading, 280-283* rotating, 280-283* H handleChatMessages function, 497* handleGameMessages function, 538-539* (client), 532-535* (server), 531-532* handleGameSync function, 525-527* handleLoginMessages function, 505*, 518-519* handleLogoutMessages function, 519-520* handlePlayerMessages function, 569-571* handlePlayerSync function, 523-524* HandleSocketInputEvent function, 344-345* header files, displaying, 101* setting up for network library, 294-295* host ID system, 318-320 host, setting offline, 303 hosts, identifying, 287 sending data to, 287 HTML footer file, 100-101* 585 Index HTML header file, 99-100* HTML, printing, 95-96* htonl function, 575 htons function, 575 HWND, I I/O, controlling, 252 functions, 252-255 strategy, 250 ID number, determining, 318-319* sending to client, 390-394* images, displaying, 273 loading, 272-273, 280-283* Include folder, 10 Inet_aton function, 212 Init function, 516-517* initialization, Windows, 193-198 InitializeWinSock function, 195-198* InitSockets function (TCP), 222-224, 234-235 (UDP), 228, 239 input/output functions, 252-255 input/output mode, setting, 355-356 Insert command, 22, 57-58 International Organization for Standardization, see ISO Internet Protocol, see IP Internet Protocol independence, 292 Ioctl function, 252-253 IoctlSocket function, 252-253 IP, 184-186 address classes, 185 addresses, 185 IPv4, 184 structure, 199-200 IPv6, 185-186 structure, 200 ISO, 182 iterative server, 190, 212-213 J JoinGame function, 512*, 530* JoinGameDialogProc function, 513-514* 586 K keyboard input, 273-274 L Lib folder, 10 Like command, 27-28 Limit parameter, 40 line, drawing, 271 Linux, building network library in, 289 file permissions, 92 installing MySQL on, 16 using to back up file, 77 Listen function, 205 little-endian order, 214 Load command, 74 loading images, 272-273 LobbyCreateAccount message, 440* LobbyCreateAccountFeedback message, 441* LobbyDialogProc function, 499-501* LobbyLogin message, 439* LobbyLoginFeedback message, 440* LobbyRefreshGameList function, 515* LobbyRefreshJoinedPlayerList function, 514-515* LobbyRefreshPlayerList function, 506* localtime function, 118 log system, 292-293 logging out from server, 503-504* LoginToServer function, 498* LogOffGame function, 531* LogoutFromServer function, 503-504* LogoutPlayer function, 520-522* LogString function, 292-293* M main function (TCP), 233-234 Max command, 38-39 message buffer class, 365 buffering system, 364 functions, 372-390* loop, 265* structure, 304-305* messages, update, 8-9 handling on client, 532-535* handling on server, 531-532* recording, 351 Index messaging system, in Windows, 3-4 Modify command, 29 Modify function, 152-156 multiplexing I/O, 252 multithreading, 247-248, 340 MySQL, 18 adding support to DBI, 120-121 creating a database in, 18-46 installing on Linux, 16 installing on Windows, 17 setting date and time with, 31 MySQL database, connecting to using Perl, 121-123* disconnecting from using Perl, 121-123* MySQL examples connecting to database and retrieving data, 84-87* updating data from an application, 87-90* MySQL++, 83-84 MySQL C++ interface, see MySQL++ mysqldump utility, 77 N native database input, 75-77 NET_Initialize function, 298*, 355* NET_InitializeWinSock function, 298-300* NET_Shutdown function, 300-301*, 355* NET_Socket class, 295-297*, 352-354* functions, 301-302 NET_UnixIOThreadFunc function, 383-386* NET_UnixPollAcceptFunc function, 401-402* NET_UnixUDPServerIOThreadFunc function, 386-390* NET_WinIOThreadFunc function, 373-375* NET_WinSockInitialize function (TCP), 221 NET_WinUDPServerIOThreadFunc function, 375-383* netLib.h, 577-582* network events, detecting, 243 handling, 344-350 network layer, 183 network library, building, 288-289 message system, 304-306 planning functionality of, 287 planning structure of, 286 platform-independent, 351 protocol-independent, 351 reasons for creating, 285-286 setting up header files for, 294-295* setting up source files for, 294-295* network library server, creating, 320-325 non-blocking function, 303-304 non-blocking I/O, 250-251 setting, 355-356 non-blocking socket, 223 ntohl function, 576 ntohs function, 575 O Open Systems Interconnection model, see OSI model openGL libraries, adding to workspace, 263 operating system independence, 290-291 Order By command, 36-37 OSI model, 182 layers, 183 P Perl, debugging, 93-94 “Hello World” example, 92-93*, 94* using to add data, 131-134* using to add search capability to form, 163-180* using to connect to a MySQL database, 121-123* using to disconnect from a MySQL database, 121-123* using to display footer file, 101* using to display header file, 101* using to display text, 112-117* using to print HTML, 95-96* using to read in text file, 96-98* using to retrieve and display data, 125-129* using to retrieve date and time, 118-119* using to write to text file, 98-99* using with forms, 103-110* using with unique ID field, 137-147* physical layer, 183 pixel, plotting, 271 platform-dependent functions, 301-351* platform-independent code, creating, 290-291 platforms, and data types, 199, 290-291 and sockets, 190 choosing, 191 587 Index Unix, 191 Windows, 191 player, removing from client, 506 playerServer_t structure, 516* ports, 187-188 Post method, 108 presentation, 183 primitives, moving, 275-280* ProcessMessageBuffer function, 366-370* ProcessMessages function, 347-350*, 370-372* project, creating, 262-263 protocol, 181-182 protocol independence, 291 protocol-independent code, creating, 291 Pthread_Create function, 249 R Read function, 306-308*, 356-358* ReadFrom function, 309-311*, 358-359* ReadToBuffer function, 365-366* RecordMessage function, 351 rectangle, drawing, 271-272 Recv function, 209 Recvfrom function, 211 relational database, 46 creating, 47-56 manipulating tables in, 70-73 structure, 46-47 release version, 12 RemoteHost class, 354-355* RemoveGame function, 529-530* removePlayer function, 506* RemovePlayer message, handling, 505* restoring databases, 81-83 S search capability, adding to form, 163-180* Select command, 24-27, 243-244 Send function, 207-208 SendDlgItemMessage function, SendMessage function, 495-496* Sendto function, 210 ServerProcess function (TCP), 224-225 (UDP), 228-229 servers, 212-213 connecting to, 329-340, 406-413* creating, 215-216, 394-406* handling messages on, 531-532* 588 logging out from, 503-504* types of, 212-213 session layer, 183 SetSockOpt function, 253-255 setting date and time, 31-33 Show Databases command, 18-19, 45, 47 Show Tables command, 20-21, 44, 49-50 Shutdown function, 255, 302, 416*, 517* signal-driven I/O, 251 socket descriptor macros, 244-245 Socket function, 202 sockets, 188 addresses of, 189-190 and platforms, 190 blocking, 223 data types of, 199 functions, 202-207 input/output functions, 207-211 non-blocking, 223 types of, 189 sockets API, 188 source files, adding to project, 263 setting up for network library, 294-295* SQL, 18 StartGame function, 538* StartLog function, 292* static libraries, adding to project, 263 static link library, 9-10 creating, 11-13 structure of, 10 using, 13 stream socket, 189 structured query language, see SQL synchronization, 543 system date, retrieving, 118-119* T tables, adding data to, 22-24 adding fields to, 28-30 adding to database, 19-22 adding to relational database, 48-56 deleting, 43-46 deleting data from, 40-43 manipulating in relational databases, 70-73 viewing data in, 24-28 TCP, 186, 216, 230 TCP client, creating, 231-233* Index TCP server, creating, 218-221* templates, using, 99-103* text file, reading, 96-98* using to enter data, 73-75 writing, 98-99* time, retrieving, 118-119* timestamp, 31 structure, 31 Transmission Control Protocol, see TCP transport layer, 183, 186 transport protocol independence, 291 triangle, drawing, 272 TutChatClass class, 495* typecasting, 201 U UDP, 187, 217, 230-231 UDP client, creating, 237-239* UDP server, creating, 225-228* unique ID field, using, 137-147* Unix, as game platform, 191 building network library in, 289 byte ordering functions, 575-576 input/output functions, 253-255 main function, 573* message functions, 383-390* multithreading in, 249 sockets functions, 202-207 sockets input/output functions, 207-211 Update command, 31-35 update message, 8-9 Use command, 19, 48 User Datagram Protocol, see UDP V Visual Studio, configuring, 261-262 using to create static link library, 11-13 using to create window, 4-6 using to find static link library, 13 W Where command, 25-28, 33-35 Win32 byte ordering functions, 575-576 input/output functions, 252-255 message functions, 372*, 373-383* sockets functions, 202-207 sockets input/output functions, 207-211 window, creating, 4-6 updating, 8-9 window handle, windowed application, creating, 264-270* Windows, as game platform, 191 building network library in, 288-289 installing MySQL on, 17 messaging system, 3-4 multithreading in, 248-249 using to back up file, 77 Windows callback procedure, see WndProc Windows Sockets, see WinSock WinHandleEvents function, 345-347*, 372 WinIOThreadFunc function, 340-344* WinMain function, 5, 7-8, 264* WinSock, 190-191 initializing, 193-198, 298-300*, 355* WM_CLOSE event, 267 WM_KEYDOWN event, 267 WM_KEYUP event, 267 WM_SIZE event, 267-268 WndProc, 5, 266* workspace, creating, 262-263 Write function, 311-313*, 359-361* WriteAll function, 315-317*, 362-364* WriteTo function, 313-314*, 361-362* WSAAsyncSelect function, 245 WSACleanup function, 194 WSAEnumProtocols function, 195 WSAEventSelect function, 245-246 WSAGetLastError function, 198 WSAStartup function, 193-194 WSAWaitForMultipleEvents function, 246-247 589 About the CD The companion CD-ROM contains all the source code from the book as well as many useful tools and applications discussed in the book The CD will autorun when you insert it in your CD drive Click the Continue button on the page that appears to view the contents (If the CD does not autorun, simply use Windows Explorer to browse the CD.) The directories and their contents are: n Software—mySQL for Linux and Windows, DBI modules for Perl, and WinZip 8.0 SHAREWARE EVALUATION version (not the registered version) n Source Code—source code from the book n Libraries—openGL 1.2 SDK, 2DLIB, and mySQL++ Also included is a partial version of NVIDIA SDK version 5.0 For more information, see NVSDK.htm in the nvidia SDK directory Note that this directory must be accessed using Windows Explorer Warning: Opening the CD package makes this book nonreturnable CD/Source Code Usage License Agreement Please read the following CD/Source Code usage license agreement before opening the CD and using the contents therein: By opening the accompanying software package, you are indicating that you have read and agree to be bound by all terms and conditions of this CD/Source Code usage license agreement The compilation of code and utilities contained on the CD and in the book are copyrighted and protected by both U.S copyright law and international copyright treaties, and is owned by Wordware Publishing, Inc Individual source code, example programs, help files, freeware, shareware, utilities, and evaluation packages, including their copyrights, are owned by the respective authors No part of the enclosed CD or this book, including all source code, help files, shareware, freeware, utilities, example programs, or evaluation programs, may be made available on a public forum (such as a World Wide Web page, FTP site, bulletin board, or Internet news group) without the express written permission of Wordware Publishing, Inc or the author of the respective source code, help files, shareware, freeware, utilities, example programs, or evaluation programs You may not decompile, reverse engineer, disassemble, create a derivative work, or otherwise use the enclosed programs, help files, freeware, shareware, utilities, or evaluation programs except as stated in this agreement The software, contained on the CD and/or as source code in this book, is sold without warranty of any kind Wordware Publishing, Inc and the authors specifically disclaim all other warranties, express or implied, including but not limited to implied warranties of merchantability and fitness for a particular purpose with respect to defects in the disk, the program, source code, sample files, help files, freeware, shareware, utilities, and evaluation programs contained therein, and/or the techniques described in the book and implemented in the example programs In no event shall Wordware Publishing, Inc., its dealers, its distributors, or the authors be liable or held responsible for any loss of profit or any other alleged or actual private or commercial damage, including but not limited to special, incidental, consequential, or other damages One (1) copy of the CD or any source code therein may be created for backup purposes The CD and all accompanying source code, sample files, help files, freeware, shareware, utilities, and evaluation programs may be copied to your hard drive With the exception of freeware and shareware programs, at no time can any part of the contents of this CD reside on more than one computer at one time The contents of the CD can be copied to another computer, as long as the contents of the CD contained on the original computer are deleted You may not include any part of the CD contents, including all source code, example programs, shareware, freeware, help files, utilities, or evaluation programs in any compilation of source code, utilities, help files, example programs, freeware, shareware, or evaluation programs on any media, including but not limited to CD, disk, or Internet distribution, without the express written permission of Wordware Publishing, Inc or the owner of the individual source code, utilities, help files, example programs, freeware, shareware, or evaluation programs You may use the source code, techniques, and example programs in your own commercial or private applications unless otherwise noted by additional usage agreements as found on the CD Warning: Opening the CD package makes this book nonreturnable ... HandleGameSync Function Creating a Game AddGame Function DestroyGame Function RemoveGame Function Joining a Game JoinGame.. .Developer s Guide to Multiplayer Games Andrew Mulholland and Teijo Hakala Wordware Publishing, Inc Library of Congress Cataloging-in-Publication Data Mulholland, Andrew Developer s guide. .. to actually make Internet games remains inadequate Developer s Guide to Multiplayer Games provides in-depth coverage of all the major topics associated with online game programming, as well as

Ngày đăng: 14/12/2018, 11:44

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan