forked from andre111/Minicraft3DS
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warning: old, unfinished code
- Loading branch information
Showing
7 changed files
with
152 additions
and
48 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,48 @@ | ||
#include "PacketHandler.h" | ||
|
||
void processPacket(networkPacket *packet, u8 type) { | ||
#include "Globals.h" | ||
|
||
void processPacket(networkPacket *packet, u8 type, u16 sender) { | ||
//TODO: Differenciate the packets and process them | ||
if(type==PACKET_REQUEST_MAPDATA) { | ||
|
||
} else if(type==PACKET_MAPDATA) { | ||
|
||
} | ||
if(networkIsServer()) { | ||
if(type==PACKET_REQUEST_MAPDATA) { | ||
u8 level = packet->requestMapData.level; | ||
|
||
if(level>=0 && level<=5) { | ||
//send back tile data | ||
for(int y=0; y<128; y++) { | ||
networkPacket packet = { | ||
.mapData = { | ||
.type = PACKET_MAPDATA, | ||
.level = level, | ||
.offset = y | ||
} | ||
}; | ||
for(int x=0; x<128; x++) { | ||
packet.mapData.map[x] = map[level][x+y*128]; | ||
packet.mapData.data[x] = data[level][x+y*128]; | ||
} | ||
networkSendTo(&packet, sizeof(packetMapData), sender); | ||
} | ||
} | ||
} else { | ||
//TODO: Unknown packet - how to handle? | ||
} | ||
} else { | ||
if(type==PACKET_MAPDATA) { | ||
u8 level = packet->mapData.level; | ||
|
||
if(level>=0 && level<=5) { | ||
//recieve tile data | ||
//TODO: This should really check whether the values are in valid range | ||
int y = packet->mapData.offset; | ||
for(int x=0; x<128; x++) { | ||
map[level][x+y*128] = packet->mapData.map[x]; | ||
data[level][x+y*128] = packet->mapData.data[x]; | ||
} | ||
} | ||
} else { | ||
//TODO: Unknown packet - how to handle? | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters