source: Daodan/src/Flatline_PacketReader.c@ 876

Last change on this file since 876 was 876, checked in by gumby, 11 years ago

Daodan pass 1

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