Sorry - problemy z RoboDoc - nie moge go rozpakowac. Recznie powycinalem co trzeba, na razie wystarczy. /****h* Strategia/Communication [1.0] * * * NAME * Communication * * COPYRIGHT * Copyright 1997 by Wociech Czyû * * FUNCTION * Communication module for UNIX strategy game * * AUTHOR * Wojciech Czyz * * CREATION DATE * Saturday 01-Nov-97 21:09:35 * * INTERNALS: Communication uses Berkley UNIX socket's as the lowest level of data movement. It will automagically hide internal mechanisms into easy to use functions. The global data route used in strategy game: Level Logical Data passing Units Unit connection e Player (Human or programmed) | | Decisions | d (Graphical) User Interface | | Events | c Player program | | Communication's function calls | b Communication (Player side) | | Socket based data passing | a Berkley sockets | | File or TCP IP data connection | 0 Network or local connection | | File or TCP IP data connection | A Berkley sockets | | Socket based data passing | B Communication (Kernel side) | | Communication's function calls | C Kernel Function of this unit is to emulate direct connection beetween Kernel (Level C) and player program (Level c). Connection beetwen C and c levels may be replaced by one logical unit - Communication module. New data flow chart: Level Logical Data passing Units Unit connection e Player (Human or programmed) | | Decisions | d (Graphical) User Interface | | Events | c Player program | | Communication's function calls | C Kernel Communication module encapsulates following sections: - Socket programming and configuration - Automatic detection of sockets - Game startup - Debugger handling * * * MODIFICATION HISTORY * Saturday 01-Nov-97 22:13:55 - Defines, structure and main function * definitions, standard function headers. * Sunday 02-Nov-97 17:39:55 - Rough body of functions, synchro for now. * Sunday 02-Nov-97 17:40:26 - Includes defined. * Sunday 02-Nov-97 18:17:43 - KConnection structure defined. * Sunday 02-Nov-97 20:26:55 - PConn structure defined. KConnection renamed * KConn. * Sunday 02-Nov-97 20:27:24 - KInitConn and PInitConn implemented. * Sunday 02-Nov-97 20:42:40 - PPutMessage recoded to use PConn structure. * Sunday 02-Nov-97 22:07:39 - Some errors removed, KInitConn, KGetMsg, * PInitConn, PPutMsg ready for test. * * NOTES * MAX_PLAYERS const must be moved to kernel module. * * HARDWARE * Any UNIX platform * ******* */ /******** Constant Definitions ********/ #define MAX_PLAYERS 10 //Must be moved to kernel //***Message types #define MSG_ERROR 0 //Error sending or getting message #define MSG_EMPTY 100 //No message to be taken #define MSG_READY 101 //Message waiting #define MSG_D_OPEN 1 // Podîâczenie sië do moduîu jâdra - deklaracja dalszego ôledzenia. // komunikatów oraz operacji jâdra. #define MSG_D_CLOSE 2 //Odîâczenie sië od moduîu jâdra. #define MSG_D_SUSPEND 3 //Zatrzymanie pracy jâdra. #define MSG_D_RESUME 4 //Wznowienie pracy jâdra. #define MSG_P_OPEN 5 //Próba podîâczenia sië do jâdra, deklaracja gracza. #define MSG_P_CLOSE 6 //Anulowanie podîâczenia sië do jâdra. #define MSG_P_READY 7 //Zgîoszenie gotowoôci do gry. #define MSG_P_WAIT 8 //Anulowanie gotowoôci do gry. #define MSG_P_PAUSE 9 //Zgîoszenie proôby o pauzë. #define MSG_P_RESUME 10 //Anulowanie proôby o pauzë #define MSG_P_END 11 //Zgîoszenie proôby o koniec gry. #define MSG_P_ENDACK 12 //Zgoda koniec gry. #define MSG_P_QUIT 13 //Natychmiastowe wstrzymanie gry (poraûka). #define MSG_P_STATUS 14 //Odczytanie statusu gracza (Atrybuty) #define MSG_P_FIELD 15 //Odczytanie zawartoôci pola. #define MSG_P_MOVE 16 //Przesuniëcie armii. #define MSG_P_WORK 17 //Zmiana pracy ludzi na danym polu. #define MSG_P_BUILD 18 //Budowanie budynku na polu. #define MSG_K_OPENACK 19 //Akceptacja/Odrzucenie poîâczenia. #define MSG_K_READYACK 20 //Potwierdzenie gotowoôci do gry. #define MSG_K_ENDACK 21 //Potwierdzenie/odrzucenie koïca gry. #define MSG_K_QUITACK 22 //Potwierdzenie wstrzymania gry. #define MSG_K_STATUSACK 23 //Podanie statusu gry/Odrzucenie ûâdania. #define MSG_K_FIELDACK 24 //Podanie zawartoôci pola/Odrzucenie ûâdania. #define MSG_K_MOVEACK 25 //Potwierdzenie przesuniëcia armii/Odrzucenie ûâdania. #define MSG_K_WORKACK 26 //Potwierdzenie zmiany pracy ludzi na danym terenie/Odrzucenie ûâdania. #define MSG_K_BUILDACK 27 //Potwierdzenie budowy budynku/Odrzucenie ûâdania. #define MSG_K_DEBUGACK 28 //Rejestracja Debuggera. #define MSG_K_SUSPENDACK 29 //Potwierdzenie zatrzymania gry. #define MSG_K_RESUMEACK 30 //Aktualnie wykonana akcja jâdra. /****** Communication/KInitConn [1.0] * * * NAME * KInitConn -- Startup kernel comm port. * * SYNOPSIS * KConn KInitConn(Players) * struct KConnect KInitConn(ULONG *) * * FUNCTION * This function will perform all what is needed to startup a game over * network. It will estabilish connection, setup players sockets and finally * begin the game. * * INPUTS * Players -- Pointer to ULONG that will hold nr of net initialized players * * RESULT * Pointer to KConn structure, that will be needed in all network calls * If pointer is NULL, something went wrong * * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * Communication/KGetMessage, Communication/KPutMessage ********** */ /****** Communication/KPutMessage [1.0] * * * NAME * KPutMessage -- Put message from kernel. * * SYNOPSIS * Message KPutMessage(MessageType, Message, Player) * ULONG KPutMessage(ULONG, struct GameMessage *, ULONG) * * FUNCTION * Send message structure from kernel to klient program. * INPUTS * MessageType -- Type of the game message, *MUST* be MSG_K_xxx * Message -- Pointer to the message structure. * Player -- Player that should get the message. * RESULT * Message type (the same as MessageType) or MSG_ERROR if something went * wrong. Global variable will hold extra explanation. * * EXAMPLE * * NOTES * KPutMessage will automatically fill in Msg field of structure. * BUGS * * SEE ALSO * Communication/KGetMessage ********** */ /****** Communication/KGetMessage [1.0] * * * NAME * KGetMessage -- Get message from Player or Debugger. * * SYNOPSIS * Message KGetMessage(Message, KC, Player) * ULONG KGetMessage(struct GameMessage *, struct KConn *, ULONG) * * FUNCTION * This function is for Kernel use only. It will get any message send by * debugger or player programs. It will try to read one or return MSG_EMPTY * if there is no one. * * INPUTS * Message -- Buffer to hold received message * KC -- Pointer to internal KConn structure created by Communication/KInitConn * Player -- Player what will send the message to kernel * RESULT * Message type or MSG_ERR if something went wrong. Global variable will hold * extra explanation. * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * ********** */ /****** Communication/PInitConn [1.0] * * * NAME * PInitConn -- Startup player comm port. * * SYNOPSIS * PConn PInitConn() * struct PConnect KInitConn(void) * * FUNCTION * This function will perform all what is needed to startup a game over * network. It will estabilish connection, setup player socket and finally * begin the game. * * INPUTS * None * * RESULT * Pointer to PConn structure, that will be needed in all network calls * If pointer is NULL, something went wrong. * * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * Communication/PGetMessage, Communication/PPutMessage ********** */ ****** Communication/PPutMessage [1.0] * * * NAME * PPutMessage -- Put message from Player * SYNOPSIS * Message PPutMessage(MsgType, Message, PC) * ULONG PPutMessage(ULONG, struct Message *, struct PConn *PC) * * FUNCTION * Send message to kernel program. PPutMessage will automatically fill in * Msg field of structure. * INPUTS * MsgType -- Type of the message, must be MSG_P_xxx. * Message -- Pointer to message that will be send. * PC -- Pointer to structure created by Communication/PInitComm. * * RESULT * Message type or MSG_ERR if something went wrong. Global variable will hold * extra explanation. * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * Communication/PInitComm, Communication/PGetMessage ********** */ /****** Communication/PGetMessage [1.0] * * * NAME * PGetMessage -- Get message from Kernel. * SYNOPSIS * * FUNCTION * This function is for Player use only. It will get any message send by * Kernel program. * INPUTS * Message structure, message type. * RESULT * Message type or MSG_ERR if something went wrong. Global variable will hold * extra explanation. * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * ********** */ /****** Communication/DPutMessage [1.0] * * * NAME * DPutMessage -- Put message from debugger * SYNOPSIS * Message DPutMessage(struct GameMessage *GM, MessageType) * FUNCTION * Send message to kernel program. PutKMessage will automatically fill in * Msg field of structure. * INPUTS * Message structure, message type. * RESULT * Message type or MSG_ERR if something went wrong. Global variable will hold * extra explanation. * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * ********** */ /****** Communication/DGetMessage [1.0] * * * NAME * DGetMessage -- Get message by debugger from Communication. * SYNOPSIS * * FUNCTION * This function is for debugger use only. It will get any message send by * kernel or player programs. * INPUTS * Message structure, message type. * RESULT * Message type or MSG_ERR if something went wrong. Global variable will hold * extra explanation. * EXAMPLE * * NOTES * * BUGS * * SEE ALSO * ********** */