source: Daodan/MSVC/Flatline_PacketReader.c@ 637

Last change on this file since 637 was 586, checked in by gumby, 14 years ago

stuff

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