MCPcopy Create free account
hub / github.com/bwapi/bwapi / processIncomingPackets

Method processIncomingPackets

bwapi/SNP_DirectIP/SNP/DirectIP.cpp:47–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45 }
46 }
47 void DirectIP::processIncomingPackets()
48 {
49 try
50 {
51 // receive all packets
52 while(true)
53 {
54 // receive next packet
55 UDPAddr sender;
56 Util::MemoryFrame packet = session.receivePacket(sender, Util::MemoryFrame(recvBufferBytes, sizeof(recvBufferBytes)));
57 if(packet.isEmpty())
58 {
59 if(session.getState() == WSAECONNRESET)
60 {
61// DropMessage(1, "target host not reachable");
62 setStatusString("host IP not reachable");
63 continue;
64 }
65 if(session.getState() == WSAEWOULDBLOCK)
66 break;
67 throw GeneralException("unhandled UDP state");
68 }
69
70 memset(sender.sin_zero, 0, sizeof(sender.sin_zero));
71
72 int type = packet.readAs<int>();
73 if(type == PacketType_RequestGameStats)
74 {
75 // -------------- PACKET: REQUEST GAME STATES -----------------------
76 if(isAdvertising)
77 {
78 // send back game stats
79 char sendBufferBytes[600];
80 Util::MemoryFrame sendBuffer(sendBufferBytes, 600);
81 Util::MemoryFrame spacket = sendBuffer;
82 spacket.writeAs<int>(PacketType_GameStats);
83 spacket.write(adData);
84 session.sendPacket(sender, sendBuffer.getFrameUpto(spacket));
85 }
86 }
87 else
88 if(type == PacketType_GameStats)
89 {
90 // -------------- PACKET: GAME STATS -------------------------------
91 // give the ad to storm
92 passAdvertisement(sender, packet);
93 }
94 else
95 if(type == PacketType_GamePacket)
96 {
97 // -------------- PACKET: GAME PACKET ------------------------------
98 // pass strom packet to strom
99 passPacket(sender, packet);
100 }
101 }
102 }
103 catch(GeneralException &e)
104 {

Callers

nothing calls this directly

Calls 13

MemoryFrameClass · 0.85
setStatusStringFunction · 0.85
GeneralExceptionClass · 0.85
passAdvertisementFunction · 0.85
passPacketFunction · 0.85
DropLastErrorFunction · 0.85
receivePacketMethod · 0.80
isEmptyMethod · 0.80
getStateMethod · 0.80
sendPacketMethod · 0.80
getFrameUptoMethod · 0.80
getMessageMethod · 0.80

Tested by

no test coverage detected