Début protocole
This commit is contained in:
		
							
								
								
									
										89
									
								
								SQCSim-common/netprotocol.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								SQCSim-common/netprotocol.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,89 @@ | ||||
| #ifndef NETPROTOCOL_H__ | ||||
| #define NETPROTOCOL_H__ | ||||
| #include "define.h" | ||||
| #include "vector3.h" | ||||
|  | ||||
| /* Protocole Particulier de Partie <20> Plusieurs Personnes (PPPPP) */ | ||||
|  | ||||
| namespace netprot { | ||||
| 	typedef uint8_t PacketType; | ||||
| 	enum PACKET_TYPE { | ||||
| 				ERR, INPUT, OUTPUT, SYNC, | ||||
| 				TEAMINF, SELFINF, PLAYINF, | ||||
| 				CHUNKMOD, PLAYERMOD, PICKUPMOD, | ||||
| 				GAMEINFO, ENDINFO , CHAT | ||||
| 			}; | ||||
|  | ||||
| 	typedef struct {					// cli -> srv			UDP			~frame | ||||
| 		Timestamp timestamp; | ||||
| 		uint8_t keys; // 0bFBLRJS__ | ||||
| 		Vector3f direction; | ||||
| 	} Input; | ||||
|  | ||||
| 	typedef struct {					// srv -> cli			UDP			~frame | ||||
| 		Timestamp timestamp; | ||||
| 		uint64_t id = 0; | ||||
| 		Vector3f position, | ||||
| 				 direction; | ||||
| 		bool is_shooting, | ||||
| 			 is_jumping; | ||||
| 	} Output; | ||||
|  | ||||
| 	typedef struct {					// srv -> cli			TCP			~second | ||||
| 		Timestamp timestamp; | ||||
| 		uint64_t sid = 0, | ||||
| 				 timer = 0; | ||||
| 		uint8_t hp = 0; | ||||
| 		uint16_t ammo = 0; | ||||
| 		Vector3f position; | ||||
| 	} Sync; | ||||
|  | ||||
| 	typedef struct {					// cli <-> srv			TCP			once | ||||
| 		char name[32]; | ||||
| 		uint64_t id = 0; | ||||
| 	} TeamInfo; | ||||
|  | ||||
| 	typedef struct {					// cli <-> srv			TCP			once | ||||
| 		char name[32]; | ||||
| 		uint64_t sid = 0, | ||||
| 				 tid = 0; | ||||
| 	} SelfInfo; | ||||
|  | ||||
| 	typedef struct {					// cli <-> srv			TCP			once | ||||
| 		char name[32]; | ||||
| 		uint64_t id = 0, | ||||
| 				 tid = 0; | ||||
| 	} PlayerInfo; | ||||
|  | ||||
| 	typedef struct { | ||||
| 		uint64_t seed; | ||||
| 		// uint8_t gameType; | ||||
| 		// uint8_t time; | ||||
| 	} GameInfo; | ||||
|  | ||||
| 	typedef struct {					// cli <-> srv			TCP			event | ||||
| 		uint64_t src_id = 0, | ||||
| 			dest_id = 0, | ||||
| 			dest_team_id = 0; | ||||
| 		char mess[140]; // Good 'nough for twitr, good 'nough for me. | ||||
| 	} Chat; | ||||
|  | ||||
| 	inline void Serialize(Input* in, char* buf, uint32_t* buflen); // cli | ||||
| 	inline void Serialize(Output* out, char* buf, uint32_t* buflen); // srv | ||||
| 	inline void Serialize(Sync* sync, char* buf, uint32_t* buflen); // srv | ||||
| 	inline void Serialize(TeamInfo* tinfo, char* buf, uint32_t* buflen); // cli/srv | ||||
| 	inline void Serialize(SelfInfo* sinfo, char* buf, uint32_t* buflen); // cli/srv | ||||
| 	inline void Serialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen); // srv | ||||
| 	inline void Serialize(Chat* chat, char* buf, uint32_t* buflen); // cli/srv | ||||
|  | ||||
| 	inline void Deserialize(Input* in, char* buf, uint32_t* buflen); // srv | ||||
| 	inline void Deserialize(Output* out, char* buf, uint32_t* buflen); // cli | ||||
| 	inline void Deserialize(Sync* sync, char* buf, uint32_t* buflen); // cli | ||||
| 	inline void Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen); // cli/srv | ||||
| 	inline void Deserialize(SelfInfo* sinfo, char* buf, uint32_t* buflen); // cli/srv | ||||
| 	inline void Deserialize(PlayerInfo* spinfoync, char* buf, uint32_t* buflen); // cli | ||||
| 	inline void Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli | ||||
|  | ||||
| 	inline PacketType getType(char* buf, uint32_t* buflen); // srv/cli | ||||
| }  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user