forked from Mirrors/openclonk
70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
/*
|
|
* OpenClonk, http://www.openclonk.org
|
|
*
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
|
* Copyright (c) 2010-2013, The OpenClonk Team and contributors
|
|
*
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
* "COPYING" for details.
|
|
*
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
* See accompanying file "TRADEMARK" for details.
|
|
*
|
|
* To redistribute this file separately, substitute the full license texts
|
|
* for the above references.
|
|
*/
|
|
|
|
#include "C4Include.h"
|
|
#include "network/C4Network2.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
class C4PuncherServer : public C4NetIOUDP, private C4NetIO::CBClass
|
|
{
|
|
public:
|
|
C4PuncherServer() { C4NetIOUDP::SetCallback(this); }
|
|
private:
|
|
// Event handlers
|
|
virtual bool OnConn(const addr_t &AddrPeer, const addr_t &AddrConnect, const addr_t *OwnAddr, C4NetIO *pNetIO)
|
|
{
|
|
printf("Punched back at %s:%d...\n", inet_ntoa(AddrPeer.sin_addr), htons(AddrPeer.sin_port));
|
|
return true;
|
|
}
|
|
virtual void OnPacket(const class C4NetIOPacket &rPacket, C4NetIO *pNetIO)
|
|
{
|
|
// Unused
|
|
}
|
|
} Puncher;
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
// Log
|
|
printf("Starting puncher...\n");
|
|
|
|
// Get port
|
|
uint16_t iPort = C4NetStdPortPuncher;
|
|
if (argc == 2)
|
|
{
|
|
iPort = strtoul(argv[1], nullptr, 10);
|
|
if (!iPort) iPort = C4NetStdPortPuncher;
|
|
}
|
|
|
|
// Initialize
|
|
if (!Puncher.Init(iPort))
|
|
{
|
|
fprintf(stderr, "Could not initialize puncher: %s", Puncher.GetError());
|
|
return 1;
|
|
}
|
|
|
|
// Log
|
|
printf("Listening on port %d...\n", iPort);
|
|
|
|
// Execute forever
|
|
Puncher.ExecuteUntil(-1);
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Necessary to satisfy the linker.
|
|
void RecordRandom(uint32_t range, uint32_t val) {}
|