mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-21 18:55:16 +00:00
Remove tabs
This commit is contained in:
parent
655368241f
commit
93c750ccf7
1 changed files with 59 additions and 59 deletions
|
@ -80,19 +80,19 @@ nn::Result SocketClient::init(const char* ip, u16 port) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) < 0) {
|
if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) < 0) {
|
||||||
Logger::log("Udp Socket failed to create");
|
Logger::log("Udp Socket failed to create");
|
||||||
this->socket_errno = nn::socket::GetLastErrno();
|
this->socket_errno = nn::socket::GetLastErrno();
|
||||||
this->socket_log_state = SOCKET_LOG_UNAVAILABLE;
|
this->socket_log_state = SOCKET_LOG_UNAVAILABLE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Find a way around the 41553 constant port
|
// TODO Find a way around the 41553 constant port
|
||||||
udpAddress.address = hostAddress;
|
udpAddress.address = hostAddress;
|
||||||
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;
|
this->has_recv_udp = false;
|
||||||
|
|
||||||
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");
|
||||||
|
@ -157,15 +157,15 @@ s32 SocketClient::setPeerUdpPort(u16 port) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* SocketClient::getUdpStateChar() {
|
const char* SocketClient::getUdpStateChar() {
|
||||||
if (this->udp_addr.port == 41553) {
|
if (this->udp_addr.port == 41553) {
|
||||||
return "Waiting for handshake";
|
return "Waiting for handshake";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->has_recv_udp) {
|
if (!this->has_recv_udp) {
|
||||||
return "Waiting for holepunch";
|
return "Waiting for holepunch";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Utilizing UDP";
|
return "Utilizing UDP";
|
||||||
}
|
}
|
||||||
bool SocketClient::send(Packet *packet) {
|
bool SocketClient::send(Packet *packet) {
|
||||||
|
|
||||||
|
@ -176,17 +176,17 @@ bool SocketClient::send(Packet *packet) {
|
||||||
|
|
||||||
int valread = 0;
|
int valread = 0;
|
||||||
|
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->has_recv_udp) {
|
if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->has_recv_udp) {
|
||||||
Logger::log("Sending packet: %s\n", packetNames[packet->mType]);
|
Logger::log("Sending packet: %s\n", packetNames[packet->mType]);
|
||||||
fd = this->socket_log_socket;
|
fd = this->socket_log_socket;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
fd = this->udp_socket;
|
fd = this->udp_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((valread = nn::socket::Send(fd, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) {
|
if ((valread = nn::socket::Send(fd, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize);
|
Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize);
|
||||||
|
@ -209,34 +209,34 @@ bool SocketClient::recv() {
|
||||||
char headerBuf[MAXPACKSIZE * 2] = {};
|
char headerBuf[MAXPACKSIZE * 2] = {};
|
||||||
int valread = 0;
|
int valread = 0;
|
||||||
|
|
||||||
const int fd_count = 2;
|
const int fd_count = 2;
|
||||||
struct pollfd pfds[fd_count] = {{0}, {0}};
|
struct pollfd pfds[fd_count] = {{0}, {0}};
|
||||||
pfds[0].fd = this->socket_log_socket;
|
pfds[0].fd = this->socket_log_socket;
|
||||||
pfds[0].events = 1;
|
pfds[0].events = 1;
|
||||||
pfds[0].revents = 0;
|
pfds[0].revents = 0;
|
||||||
pfds[1].fd = this->udp_socket;
|
pfds[1].fd = this->udp_socket;
|
||||||
pfds[1].events = 1;
|
pfds[1].events = 1;
|
||||||
pfds[1].revents = 0;
|
pfds[1].revents = 0;
|
||||||
|
|
||||||
|
|
||||||
if (nn::socket::Poll(pfds, fd_count, 0) <= 0) {
|
if (nn::socket::Poll(pfds, fd_count, 0) <= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 fd = -1;
|
s32 fd = -1;
|
||||||
s32 index = -1;
|
s32 index = -1;
|
||||||
for (int i = 0; i < fd_count; i++){
|
for (int i = 0; i < fd_count; i++){
|
||||||
if (pfds[i].revents & 1) {
|
if (pfds[i].revents & 1) {
|
||||||
fd = pfds[i].fd;
|
fd = pfds[i].fd;
|
||||||
index = i;
|
index = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == 1) {
|
if (index == 1) {
|
||||||
int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags);
|
int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags);
|
||||||
if (result < headerSize){
|
if (result < headerSize){
|
||||||
return true;
|
return true;
|
||||||
|
@ -244,40 +244,40 @@ 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
|
// Verify packet size is appropriate
|
||||||
if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){
|
if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify type of packet
|
// 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);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->has_recv_udp = true;
|
this->has_recv_udp = true;
|
||||||
|
|
||||||
char* packetBuf = (char*)mHeap->alloc(fullSize);
|
char* packetBuf = (char*)mHeap->alloc(fullSize);
|
||||||
if (packetBuf){
|
if (packetBuf){
|
||||||
memcpy(packetBuf, headerBuf, fullSize);
|
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);
|
||||||
} else {
|
} else {
|
||||||
mHeap->free(packetBuf);
|
mHeap->free(packetBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read only the size of a header
|
// read only the size of a header
|
||||||
while(valread < headerSize) {
|
while(valread < headerSize) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
result = nn::socket::Recv(fd, headerBuf + valread,
|
result = nn::socket::Recv(fd, headerBuf + valread,
|
||||||
headerSize - valread, this->sock_flags);
|
headerSize - valread, this->sock_flags);
|
||||||
|
|
||||||
this->socket_errno = nn::socket::GetLastErrno();
|
this->socket_errno = nn::socket::GetLastErrno();
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ bool SocketClient::closeSocket() {
|
||||||
|
|
||||||
Logger::log("Closing Socket.\n");
|
Logger::log("Closing Socket.\n");
|
||||||
|
|
||||||
has_recv_udp = false;
|
has_recv_udp = false;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (!(result = SocketBase::closeSocket())) {
|
if (!(result = SocketBase::closeSocket())) {
|
||||||
|
|
Loading…
Reference in a new issue