source: Daodan/src/flatline/Flatline_PacketReader.c@ 953

Last change on this file since 953 was 881, checked in by alloc, 11 years ago

Daodan: Some flatline cleanups

File size: 4.5 KB
RevLine 
[876]1#include "Flatline.h"
[881]2#include "Flatline_Packet.h"
[876]3
4bool DoWeUpdateThis( uint16_t BitSet, uint16_t Flag )
5{
6 if( BitSet & (1 << Flag) ) return true;
7 return false;
8}
9
10//Long winded?
11
12
13
14void FLcPacketBufferToPlayerData( PlayerData* PD)
15{
16 player_info* PI = PlayerList[PD->ID];
17 uint8_t * DataPointer = PD->data;
18
19 static player_info BufferData[MAX_PLAYERS] = {0};
20 static bool IsBuffered[32];
21
22
23 if(!PI)
24 {
25 //TODO: Store this data and then apply it once we have a character that matches!
26 flatline_packet pk;
27 pk.id = PK_MISSING_PLAYER;
28 pk.integer = PD->ID;
29 DDrConsole_Print("input");
30 NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&pk, FLATLINE_HEADER + 4 );
31
32 IsBuffered[PD->ID] = 1;
33 PI = &BufferData[PD->ID];
34
35 //return;
36 }
37 else if(IsBuffered[PD->ID])
38 {
39 player_info* Buffer = BufferData + PD->ID;
40 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Input) ) PI->Input = Buffer->Input;
41 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Facing) ) PI->Facings = Buffer->Facings;
42 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Health) ) PI->Health = Buffer->Health;
43 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_FramePing) ) {
44 PI->Frame = Buffer->Frame;
45 PI->Ping = Buffer->Ping;
46 }
47 //if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Inventory) ) PI->invi= Buffer->Input;
48 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Class) )
49 {
50 PI->Class = Buffer->Class;
51 /*THIS MIGHT BE BAD*/ snprintf( PI->ClassString, 32, "%s", Buffer->ClassString );
52 }
53
54 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Position) ) PI->Position = Buffer->Position;
55 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Animation) )
56 {
57 PI->Animation = Buffer->Animation;
58 /*THIS MIGHT BE BAD*/ snprintf( PI->AnimationString, 32, "%s", Buffer->AnimationString);
59 }
60 if( DoWeUpdateThis( Buffer->UpdateFlags, PFlag_Throws) ) PI->ThrowData = Buffer->ThrowData;
61
62 PI->UpdateFlags |= Buffer->UpdateFlags;
63 IsBuffered[PD->ID] = 0;
64 }
65
66 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Input) )
67 {
68 PI->Input = *(PlayerInput*)DataPointer;
69 DataPointer += FLpData_PartSize( PFlag_Input);
70 }
71
72 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Facing) )
73 {
74 PI->Facings = *(PlayerFacing*)DataPointer;
75 DataPointer += FLpData_PartSize( PFlag_Facing);
76 }
77
78 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Health) )
79 {
80 PI->Health = *(PlayerHealth*)DataPointer;
81 DataPointer += FLpData_PartSize( PFlag_Health);
82 }
83
84 //Not done
85 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Score) )
86 {
87 PI->Score = *(PlayerScore*)DataPointer;
88 DataPointer += FLpData_PartSize( PFlag_Score);
89 }
90
91 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_FramePing) )
92 {
93 PlayerFP* FP = (PlayerFP*)DataPointer;
94 PI->Ping = FP->Ping;
95
96 if(FP->Frame != -1)
97 {
98 PI->Frame = FP->Frame;
99 }
100 else
101 {
102 PD->UpdateFlags &= ~( 1 << PFlag_FramePing );
103 }
104 DataPointer += FLpData_PartSize( PFlag_FramePing);
105 }
106
107 //Not done
108 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Inventory) )
109 {
110 PI->Inventory = *(PlayerInventory*)DataPointer;
111 DataPointer += FLpData_PartSize( PFlag_Inventory );
112 }
113
114 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Class ) )
115 {
116 /*THIS MIGHT BE BAD*/ snprintf( PI->ClassString, 32, "%s", DataPointer );
117 TMrInstance_GetDataPtr( 'ONCC', (char*)DataPointer, &PI->Class );
118 DataPointer += FLpData_PartSize( PFlag_Class );
119 }
120
121 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Position ) )
122 {
123 PI->Position = *(Vector3*)DataPointer;
124 DataPointer += FLpData_PartSize( PFlag_Position );
125 }
126
127 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Animation ) )
128 {
129 /*THIS MIGHT BE BAD*/ snprintf( PI->AnimationString, 32, "%s", DataPointer );
130 TMrInstance_GetDataPtr( 'TRAM', PI->AnimationString, &PI->Animation );
131 DataPointer += FLpData_PartSize( PFlag_Animation );
132 }
133
134 if( DoWeUpdateThis( PD->UpdateFlags, PFlag_Throws ) )
135 {
136 PI->ThrowData = *(PlayerThrowData*)DataPointer;
137 DataPointer += FLpData_PartSize( PFlag_Throws );
138 }
139
140
141 PI->UpdateFlags |= PD->UpdateFlags;
142}
143
144void FLcReadPlayerData( flatline_packet* Packet, int16_t Size )
145{
146 PlayerData* PDCast = (PlayerData*)Packet->data;
147 Size -= FLATLINE_HEADER;
148 while(Size > 0)
149 {
150 if(PDCast->Size > Size)
151 {
152 DDrConsole_PrintF( "Warning, (almost) read %hi bytes too much of player data buffer", -Size );
153 break;
154 }
155 FLcPacketBufferToPlayerData( PDCast );
156 Size -= PDCast->Size;
157 PDCast = (PlayerData*)((char*)PDCast + PDCast->Size);
158 }
159
160 //Packet
[881]161}
Note: See TracBrowser for help on using the repository browser.