mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-22 03:05:16 +00:00
Allow for a udp handshake
This commit is contained in:
parent
968f513bf2
commit
694c9e73d6
4 changed files with 71 additions and 19 deletions
|
@ -197,6 +197,8 @@ class Client {
|
||||||
void updateTagInfo(TagInf *packet);
|
void updateTagInfo(TagInf *packet);
|
||||||
void updateCaptureInfo(CaptureInf* packet);
|
void updateCaptureInfo(CaptureInf* packet);
|
||||||
void sendToStage(ChangeStagePacket* packet);
|
void sendToStage(ChangeStagePacket* packet);
|
||||||
|
void sendUdpHolePunch();
|
||||||
|
void sendUdpInit();
|
||||||
void disconnectPlayer(PlayerDC *packet);
|
void disconnectPlayer(PlayerDC *packet);
|
||||||
|
|
||||||
PuppetInfo* findPuppetInfo(const nn::account::Uid& id, bool isFindAvailable);
|
PuppetInfo* findPuppetInfo(const nn::account::Uid& id, bool isFindAvailable);
|
||||||
|
|
|
@ -44,7 +44,7 @@ class SocketClient : public SocketBase {
|
||||||
void printPacket(Packet* packet);
|
void printPacket(Packet* packet);
|
||||||
bool isConnected() { return socket_log_state == SOCKET_LOG_CONNECTED; }
|
bool isConnected() { return socket_log_state == SOCKET_LOG_CONNECTED; }
|
||||||
|
|
||||||
u16 getUdpPort();
|
u16 getLocalUdpPort();
|
||||||
s32 setPeerUdpPort(u16 port);
|
s32 setPeerUdpPort(u16 port);
|
||||||
|
|
||||||
u32 getSendCount() { return mSendQueue.getCount(); }
|
u32 getSendCount() { return mSendQueue.getCount(); }
|
||||||
|
|
|
@ -383,6 +383,19 @@ void Client::readFunc() {
|
||||||
maxPuppets = initPacket->maxPlayers - 1;
|
maxPuppets = initPacket->maxPlayers - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PacketType::UDPINIT: {
|
||||||
|
UdpInit* initPacket = (UdpInit*)curPacket;
|
||||||
|
Logger::log("Received udp init packet from server");
|
||||||
|
|
||||||
|
sInstance->mSocket->setPeerUdpPort(initPacket->port);
|
||||||
|
sendUdpHolePunch();
|
||||||
|
sendUdpInit();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PacketType::HOLEPUNCH:
|
||||||
|
sendUdpHolePunch();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Logger::log("Discarding Unknown Packet Type.\n");
|
Logger::log("Discarding Unknown Packet Type.\n");
|
||||||
break;
|
break;
|
||||||
|
@ -939,7 +952,45 @@ void Client::sendToStage(ChangeStagePacket* packet) {
|
||||||
GameDataFunction::tryChangeNextStage(accessor, &info);
|
GameDataFunction::tryChangeNextStage(accessor, &info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Send a udp holepunch packet to the server
|
||||||
|
*/
|
||||||
|
void Client::sendUdpHolePunch() {
|
||||||
|
|
||||||
|
if (!sInstance) {
|
||||||
|
Logger::log("Static Instance is Null!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sead::ScopedCurrentHeapSetter setter(sInstance->mHeap);
|
||||||
|
|
||||||
|
HolePunch *packet = new HolePunch();
|
||||||
|
|
||||||
|
packet->mUserID = sInstance->mUserID;
|
||||||
|
|
||||||
|
sInstance->mSocket->queuePacket(packet);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Send a udp init packet to server
|
||||||
|
*/
|
||||||
|
void Client::sendUdpInit() {
|
||||||
|
|
||||||
|
if (!sInstance) {
|
||||||
|
Logger::log("Static Instance is Null!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sead::ScopedCurrentHeapSetter setter(sInstance->mHeap);
|
||||||
|
|
||||||
|
UdpInit *packet = new UdpInit();
|
||||||
|
|
||||||
|
packet->mUserID = sInstance->mUserID;
|
||||||
|
packet->port = sInstance->mSocket->getLocalUdpPort();
|
||||||
|
|
||||||
|
sInstance->mSocket->queuePacket(packet);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
|
|
|
@ -91,10 +91,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) {
|
||||||
udpAddress.port = nn::socket::InetHtons(41553);
|
udpAddress.port = nn::socket::InetHtons(41553);
|
||||||
udpAddress.family = 2;
|
udpAddress.family = 2;
|
||||||
this->udp_addr = udpAddress;
|
this->udp_addr = udpAddress;
|
||||||
|
this->has_recv_udp = false;
|
||||||
// udpAddress.address = hostAddress;
|
|
||||||
// udpAddress.port = nn::socket::InetHtons(57734);
|
|
||||||
// udpAddress.family = 2;
|
|
||||||
|
|
||||||
if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) {
|
if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) {
|
||||||
Logger::log("Udp Socket Connection Failed!\n");
|
Logger::log("Udp Socket Connection Failed!\n");
|
||||||
|
@ -128,7 +125,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 SocketClient::getUdpPort() {
|
u16 SocketClient::getLocalUdpPort() {
|
||||||
sockaddr udpAddress = { 0 };
|
sockaddr udpAddress = { 0 };
|
||||||
u32 size = sizeof(udpAddress);
|
u32 size = sizeof(udpAddress);
|
||||||
|
|
||||||
|
@ -235,30 +232,32 @@ bool SocketClient::recv() {
|
||||||
|
|
||||||
Packet* header = reinterpret_cast<Packet*>(headerBuf);
|
Packet* header = reinterpret_cast<Packet*>(headerBuf);
|
||||||
int fullSize = header->mPacketSize + sizeof(Packet);
|
int fullSize = header->mPacketSize + sizeof(Packet);
|
||||||
|
// Verify packet size is appropriate
|
||||||
if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){
|
if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* packetBuf = (char*)malloc(fullSize);
|
// Verify type of packet
|
||||||
|
|
||||||
if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) {
|
if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) {
|
||||||
Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, result);
|
Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, result);
|
||||||
free(packetBuf);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(packetBuf, headerBuf, fullSize);
|
this->has_recv_udp = true;
|
||||||
|
|
||||||
|
char* packetBuf = (char*)mHeap->alloc(fullSize);
|
||||||
|
if (packetBuf){
|
||||||
|
memcpy(packetBuf, headerBuf, fullSize);
|
||||||
|
|
||||||
|
|
||||||
Packet *packet = reinterpret_cast<Packet*>(packetBuf);
|
Packet *packet = reinterpret_cast<Packet*>(packetBuf);
|
||||||
|
|
||||||
if(!mRecvQueue.isFull()) {
|
if(!mRecvQueue.isFull()) {
|
||||||
mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking);
|
mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking);
|
||||||
this->has_recv_udp = true;
|
} else {
|
||||||
} else {
|
mHeap->free(packetBuf);
|
||||||
free(packetBuf);
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue