lay base for LAN

This commit is contained in:
Arisotura 2023-09-02 21:06:04 +02:00
parent b9e8e1eb49
commit ba6747c050
5 changed files with 172 additions and 6 deletions

View File

@ -26,6 +26,7 @@ set(SOURCES_QT_SDL
TitleManagerDialog.cpp
Input.cpp
IPC.cpp
LAN.cpp
LAN_PCap.cpp
LAN_Socket.cpp
Netplay.cpp

View File

@ -98,9 +98,6 @@ const u32 kMPReplyEnd = kBufferSize;
int MPRecvTimeout;
int MPLastHostID;
int MPRecvTimeout;
int MPLastHostID;
// we need to come up with our own abstraction layer for named semaphores
// because QSystemSemaphore doesn't support waiting with a timeout
// and, as such, is unsuitable to our needs

116
src/frontend/qt_sdl/LAN.cpp Normal file
View File

@ -0,0 +1,116 @@
/*
Copyright 2016-2022 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//
#include "LAN.h"
#include "Config.h"
//#include "main.h"
//
//extern EmuThread* emuThread;
namespace LAN
{
//
bool Init()
{
//
return true;
}
void DeInit()
{
//
}
void SetMPRecvTimeout(int timeout)
{
//MPRecvTimeout = timeout;
}
void MPBegin()
{
//
}
void MPEnd()
{
//
}
void SetActive(bool active)
{
//
}
u16 GetInstanceBitmask()
{
//
return 0;
}
int SendMPPacket(u8* packet, int len, u64 timestamp)
{
return 0;
}
int RecvMPPacket(u8* packet, u64* timestamp)
{
return 0;
}
int SendMPCmd(u8* packet, int len, u64 timestamp)
{
return 0;
}
int SendMPReply(u8* packet, int len, u64 timestamp, u16 aid)
{
return 0;
}
int SendMPAck(u8* packet, int len, u64 timestamp)
{
return 0;
}
int RecvMPHostPacket(u8* packet, u64* timestamp)
{
return 0;
}
u16 RecvMPReplies(u8* packets, u64 timestamp, u16 aidmask)
{
return 0;
}
}

50
src/frontend/qt_sdl/LAN.h Normal file
View File

@ -0,0 +1,50 @@
/*
Copyright 2016-2022 melonDS team
This file is part of melonDS.
melonDS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#ifndef LAN_H
#define LAN_H
#include <string>
#include "types.h"
namespace LAN
{
bool Init();
void DeInit();
void SetMPRecvTimeout(int timeout);
void MPBegin();
void MPEnd();
void SetActive(bool active);
u16 GetInstanceBitmask();
int SendMPPacket(u8* data, int len, u64 timestamp);
int RecvMPPacket(u8* data, u64* timestamp);
int SendMPCmd(u8* data, int len, u64 timestamp);
int SendMPReply(u8* data, int len, u64 timestamp, u16 aid);
int SendMPAck(u8* data, int len, u64 timestamp);
int RecvMPHostPacket(u8* data, u64* timestamp);
u16 RecvMPReplies(u8* data, u64 timestamp, u16 aidmask);
}
#endif // LAN_H

View File

@ -633,6 +633,7 @@ printf("[MC] finish blob type=%d len=%d\n", type, len);
// load initial state
// TODO: terrible hack!!
#if 0
FILE* f = Platform::OpenFile("netplay2.mln", "wb");
fwrite(Blobs[Blob_InitState], BlobLens[Blob_InitState], 1, f);
fclose(f);
@ -654,6 +655,7 @@ printf("[MC] finish blob type=%d len=%d\n", type, len);
printf("[MC] state loaded, PC=%08X/%08X\n", NDS::GetPC(0), NDS::GetPC(1));
ENetPacket* resp = enet_packet_create(buf, 1, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(peer, 1, resp);
#endif
}
else if (buf[0] == 0x05)
{
@ -666,12 +668,12 @@ void SyncMirrorClients()
{
printf("[MIRROR HOST] syncing clients\n");
SendBlobToMirrorClients(Blob_CartROM, NDSCart::CartROMSize, NDSCart::CartROM);
//SendBlobToMirrorClients(Blob_CartROM, NDSCart::CartROMSize, NDSCart::CartROM);
SendBlobToMirrorClients(Blob_CartSRAM, NDSCart::GetSaveMemoryLength(), NDSCart::GetSaveMemory());
// send initial state
// TODO: this is a terrible hack!
printf("[MH] state start\n");
/*printf("[MH] state start\n");
Savestate* state = new Savestate("netplay.mln", true);
NDS::DoSavestate(state);
delete state;
@ -687,7 +689,7 @@ void SyncMirrorClients()
printf("[MH] state read, len=%d\n", flen);
SendBlobToMirrorClients(Blob_InitState, flen, statebuf);
printf("[MH] state sent\n");
delete[] statebuf;
delete[] statebuf;*/
u8 data[2];
data[0] = 0x04;