Revert "Update Link code to use SMFL Version 2" and "Enable link functionality by default"

This reverts commit 9a359f5b8e.
This reverts commit 3d3229f899.
This commit is contained in:
Arthur Moore 2015-04-10 02:52:14 -04:00
parent bc6f047c44
commit 06c753fe25
6 changed files with 85 additions and 90 deletions

View File

@ -18,7 +18,7 @@ option( ENABLE_NLS "Enable translations" ON )
option( ENABLE_ASM_CORE "Enable x86 ASM CPU cores" OFF )
option( ENABLE_ASM_SCALERS "Enable x86 ASM graphic filters" OFF )
option( ENABLE_MMX "Enable MMX" OFF )
option( ENABLE_LINK "Enable GBA linking functionality" ON )
option( ENABLE_LINK "Enable GBA linking functionality" OFF )
option( ENABLE_LIRC "Enable LIRC support" OFF )
option( ENABLE_FFMPEG "Enable ffmpeg A/V recording" OFF )
if(ENABLE_ASM_SCALERS)

View File

@ -162,7 +162,7 @@ int WaitForSingleObject(sem_t *s, int t)
int linktime = 0;
GBASockClient* dol = NULL;
sf::IpAddress joybusHostAddr = sf::IpAddress::LocalHost;
sf::IPAddress joybusHostAddr = sf::IPAddress::LocalHost;
// Hodgepodge
u8 tspeed = 3;
@ -1105,7 +1105,7 @@ void CloseLink(void){
char outbuffer[4];
outbuffer[0] = 4;
outbuffer[1] = -32;
if(lanlink.type==0) lanlink.tcpsocket.send(outbuffer, 4);
if(lanlink.type==0) lanlink.tcpsocket.Send(outbuffer, 4);
} else {
char outbuffer[12];
int i;
@ -1113,9 +1113,9 @@ void CloseLink(void){
outbuffer[1] = -32;
for(i=1;i<=lanlink.numslaves;i++){
if(lanlink.type==0){
ls.tcpsocket[i].send(outbuffer, 12);
ls.tcpsocket[i].Send(outbuffer, 12);
}
ls.tcpsocket[i].disconnect();
ls.tcpsocket[i].Close();
}
}
}
@ -1187,7 +1187,7 @@ lserver::lserver(void){
bool lserver::Init(ServerInfoDisplay *sid){
// too bad Listen() doesn't take an address as well
// then again, old code used INADDR_ANY anyway
if(!lanlink.listener.listen(IP_LINK_PORT))
if(!lanlink.tcpsocket.Listen(IP_LINK_PORT))
// Note: old code closed socket & retried once on bind failure
return false; // FIXME: error code?
@ -1200,10 +1200,10 @@ bool lserver::Init(ServerInfoDisplay *sid){
linkid = 0;
// should probably use GetPublicAddress()
sid->ShowServerIP(sf::IpAddress::getLocalAddress());
sid->ShowServerIP(sf::IPAddress::GetLocalAddress());
lanlink.thread = new sf::Thread(LinkServerThread, sid);
lanlink.thread->launch();
lanlink.thread->Launch();
return true;
@ -1211,7 +1211,7 @@ bool lserver::Init(ServerInfoDisplay *sid){
void LinkServerThread(void *_sid){
ServerInfoDisplay *sid = (ServerInfoDisplay *)_sid;
sf::SocketSelector fdset;
sf::Selector<sf::SocketTCP> fdset;
char inbuffer[256], outbuffer[256];
s32 *intinbuffer = (s32*)inbuffer;
u16 *u16inbuffer = (u16*)inbuffer;
@ -1221,24 +1221,24 @@ void LinkServerThread(void *_sid){
i = 0;
while(i<lanlink.numslaves){
fdset.clear();
fdset.add(lanlink.tcpsocket);
fdset.Clear();
fdset.Add(lanlink.tcpsocket);
if(lanlink.terminate){
ReleaseSemaphore(linksync[vbaid], 1, NULL);
goto CloseInfoDisplay;
}
if(fdset.wait(sf::seconds(0.1))==1){
if(fdset.Wait(0.1)==1){
sf::Socket::Status st =
lanlink.listener.accept(ls.tcpsocket[i+1]);
lanlink.tcpsocket.Accept(ls.tcpsocket[i+1]);
if(st == sf::Socket::Error) {
for(int j=1;j<i;j++) ls.tcpsocket[j].disconnect();
for(int j=1;j<i;j++) ls.tcpsocket[j].Close();
systemMessage(0, N_("Network error."));
lanlink.terminate = true;
} else {
i++;
WRITE16LE(&u16outbuffer[0], i);
WRITE16LE(&u16outbuffer[1], lanlink.numslaves);
ls.tcpsocket[i].send(outbuffer, 4);
ls.tcpsocket[i].Send(outbuffer, 4);
sid->ShowConnect(i);
}
}
@ -1251,7 +1251,7 @@ void LinkServerThread(void *_sid){
for(i=1;i<=lanlink.numslaves;i++){
outbuffer[0] = 4;
ls.tcpsocket[i].send(outbuffer, 4);
ls.tcpsocket[i].Send(outbuffer, 4);
}
CloseInfoDisplay:
@ -1265,9 +1265,9 @@ void lserver::Send(void){
outbuffer[0] = 4;
outbuffer[1] = -32; //0xe0
for(i=1;i<=lanlink.numslaves;i++){
tcpsocket[i].send(outbuffer, 4);
tcpsocket[i].Send(outbuffer, 4);
size_t nr;
tcpsocket[i].receive(inbuffer, 4, nr);
tcpsocket[i].Receive(inbuffer, 4, nr);
}
}
outbuffer[1] = tspeed;
@ -1276,27 +1276,27 @@ void lserver::Send(void){
if(lanlink.numslaves==1){
if(lanlink.type==0){
outbuffer[0] = 8;
tcpsocket[1].send(outbuffer, 8);
tcpsocket[1].Send(outbuffer, 8);
}
}
else if(lanlink.numslaves==2){
WRITE16LE(&u16outbuffer[4], linkdata[2]);
if(lanlink.type==0){
outbuffer[0] = 10;
tcpsocket[1].send(outbuffer, 10);
tcpsocket[1].Send(outbuffer, 10);
WRITE16LE(&u16outbuffer[4], linkdata[1]);
tcpsocket[2].send(outbuffer, 10);
tcpsocket[2].Send(outbuffer, 10);
}
} else {
if(lanlink.type==0){
outbuffer[0] = 12;
WRITE16LE(&u16outbuffer[4], linkdata[2]);
WRITE16LE(&u16outbuffer[5], linkdata[3]);
tcpsocket[1].send(outbuffer, 12);
tcpsocket[1].Send(outbuffer, 12);
WRITE16LE(&u16outbuffer[4], linkdata[1]);
tcpsocket[2].send(outbuffer, 12);
tcpsocket[2].Send(outbuffer, 12);
WRITE16LE(&u16outbuffer[5], linkdata[2]);
tcpsocket[3].send(outbuffer, 12);
tcpsocket[3].Send(outbuffer, 12);
}
}
}
@ -1306,10 +1306,10 @@ void lserver::Send(void){
void lserver::Recv(void){
int numbytes;
if(lanlink.type==0){ // TCP
fdset.clear();
for(i=0;i<lanlink.numslaves;i++) fdset.add(tcpsocket[i+1]);
fdset.Clear();
for(i=0;i<lanlink.numslaves;i++) fdset.Add(tcpsocket[i+1]);
// was linktimeout/1000 (i.e., drop ms part), but that's wrong
if (fdset.wait(sf::seconds((float)(linktimeout / 1000.))) == 0)
if (fdset.Wait((float)(linktimeout / 1000.)) == 0)
{
return;
}
@ -1319,7 +1319,7 @@ void lserver::Recv(void){
inbuffer[0] = 1;
while(numbytes<howmanytimes*inbuffer[0]) {
size_t nr;
tcpsocket[i+1].receive(inbuffer+numbytes, howmanytimes*inbuffer[0]-numbytes, nr);
tcpsocket[i+1].Receive(inbuffer+numbytes, howmanytimes*inbuffer[0]-numbytes, nr);
numbytes += nr;
}
if(howmanytimes>1) memmove(inbuffer, inbuffer+inbuffer[0]*(howmanytimes-1), inbuffer[0]);
@ -1331,10 +1331,10 @@ void lserver::Recv(void){
outbuffer[0] = 4;
outbuffer[1] = -32;
for(i=1;i<lanlink.numslaves;i++){
tcpsocket[i].send(outbuffer, 12);
tcpsocket[i].Send(outbuffer, 12);
size_t nr;
tcpsocket[i].receive(inbuffer, 256, nr);
tcpsocket[i].disconnect();
tcpsocket[i].Receive(inbuffer, 256, nr);
tcpsocket[i].Close();
}
return;
}
@ -1357,10 +1357,10 @@ lclient::lclient(void){
return;
}
bool lclient::Init(sf::IpAddress addr, ClientInfoDisplay *cid){
bool lclient::Init(sf::IPAddress addr, ClientInfoDisplay *cid){
serveraddr = addr;
serverport = IP_LINK_PORT;
lanlink.tcpsocket.setBlocking(false);
lanlink.tcpsocket.SetBlocking(false);
if(lanlink.thread!=NULL){
lanlink.terminate = true;
@ -1371,19 +1371,19 @@ bool lclient::Init(sf::IpAddress addr, ClientInfoDisplay *cid){
cid->ConnectStart(addr);
lanlink.terminate = false;
lanlink.thread = new sf::Thread(LinkClientThread, cid);
lanlink.thread->launch();
lanlink.thread->Launch();
return true;
}
void LinkClientThread(void *_cid){
ClientInfoDisplay *cid = (ClientInfoDisplay *)_cid;
sf::SocketSelector fdset;
sf::Selector<sf::SocketTCP> fdset;
int numbytes;
char inbuffer[16];
u16 *u16inbuffer = (u16*)inbuffer;
unsigned long block = 0;
while(lanlink.tcpsocket.connect(lc.serveraddr, lc.serverport) != sf::Socket::Done) {
while(lanlink.tcpsocket.Connect(lc.serverport, lc.serveraddr) != sf::Socket::Done) {
// stupid SFML has no way of giving what sort of error occurred
// so we'll just have to do a retry loop, I guess.
cid->Ping();
@ -1403,14 +1403,14 @@ void LinkClientThread(void *_cid){
numbytes = 0;
size_t got;
while(numbytes<4) {
lanlink.tcpsocket.receive(inbuffer+numbytes, 4 - numbytes, got);
lanlink.tcpsocket.Receive(inbuffer+numbytes, 4 - numbytes, got);
numbytes += got;
fdset.clear();
fdset.add(lanlink.tcpsocket);
fdset.wait(sf::seconds(0.1));
fdset.Clear();
fdset.Add(lanlink.tcpsocket);
fdset.Wait(0.1);
cid->Ping();
if(lanlink.terminate) {
lanlink.tcpsocket.disconnect();
lanlink.tcpsocket.Close();
goto CloseInfoDisplay;
}
}
@ -1422,14 +1422,14 @@ void LinkClientThread(void *_cid){
numbytes = 0;
inbuffer[0] = 1;
while(numbytes<inbuffer[0]) {
lanlink.tcpsocket.receive(inbuffer+numbytes, inbuffer[0] - got, got);
lanlink.tcpsocket.Receive(inbuffer+numbytes, inbuffer[0] - got, got);
numbytes += got;
fdset.clear();
fdset.add(lanlink.tcpsocket);
fdset.wait(sf::seconds(0.1));
fdset.Clear();
fdset.Add(lanlink.tcpsocket);
fdset.Wait(0.1);
cid->Ping();
if(lanlink.terminate) {
lanlink.tcpsocket.disconnect();
lanlink.tcpsocket.Close();
goto CloseInfoDisplay;
}
}
@ -1445,16 +1445,16 @@ CloseInfoDisplay:
void lclient::CheckConn(void){
size_t nr;
lanlink.tcpsocket.receive(inbuffer, 1, nr);
lanlink.tcpsocket.Receive(inbuffer, 1, nr);
numbytes = nr;
if(numbytes>0){
while(numbytes<inbuffer[0]) {
lanlink.tcpsocket.receive(inbuffer+numbytes, inbuffer[0] - numbytes, nr);
lanlink.tcpsocket.Receive(inbuffer+numbytes, inbuffer[0] - numbytes, nr);
numbytes += nr;
}
if(inbuffer[1]==-32){
outbuffer[0] = 4;
lanlink.tcpsocket.send(outbuffer, 4);
lanlink.tcpsocket.Send(outbuffer, 4);
lanlink.connected = false;
systemScreenMessage(_("Server disconnected."));
return;
@ -1475,11 +1475,11 @@ void lclient::CheckConn(void){
}
void lclient::Recv(void){
fdset.clear();
fdset.Clear();
// old code used socket # instead of mask again
fdset.add(lanlink.tcpsocket);
fdset.Add(lanlink.tcpsocket);
// old code stripped off ms again
if (fdset.wait(sf::seconds((float)(linktimeout / 1000.))) == 0)
if (fdset.Wait((float)(linktimeout / 1000.)) == 0)
{
numtransfers = 0;
return;
@ -1488,12 +1488,12 @@ void lclient::Recv(void){
inbuffer[0] = 1;
size_t nr;
while(numbytes<inbuffer[0]) {
lanlink.tcpsocket.receive(inbuffer+numbytes, inbuffer[0] - numbytes, nr);
lanlink.tcpsocket.Receive(inbuffer+numbytes, inbuffer[0] - numbytes, nr);
numbytes += nr;
}
if(inbuffer[1]==-32){
outbuffer[0] = 4;
lanlink.tcpsocket.send(outbuffer, 4);
lanlink.tcpsocket.Send(outbuffer, 4);
lanlink.connected = false;
systemScreenMessage(_("Server disconnected."));
return;
@ -1515,7 +1515,7 @@ void lclient::Send(){
outbuffer[0] = 4;
outbuffer[1] = linkid<<2;
WRITE16LE(&u16outbuffer[1], linkdata[linkid]);
lanlink.tcpsocket.send(outbuffer, 4);
lanlink.tcpsocket.Send(outbuffer, 4);
return;
}
#endif

View File

@ -1,7 +1,6 @@
#ifndef GBA_GBALINK_H
#define GBA_GBALINK_H
#pragma once
// register definitions; these are always present
@ -55,9 +54,6 @@ enum
extern const char *MakeInstanceFilename(const char *Input);
#ifndef NO_LINK
//Fix for X.h breaking things
#undef None
// Link implementation
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
@ -65,7 +61,7 @@ extern const char *MakeInstanceFilename(const char *Input);
class ServerInfoDisplay
{
public:
virtual void ShowServerIP(const sf::IpAddress& addr) = 0;
virtual void ShowServerIP(const sf::IPAddress& addr) = 0;
virtual void ShowConnect(const int player) = 0;
virtual void Ping() = 0;
virtual void Connected() = 0;
@ -88,7 +84,7 @@ typedef struct {
class lserver{
int numbytes;
sf::SocketSelector fdset;
sf::Selector<sf::SocketTCP> fdset;
//timeval udptimeout;
char inbuffer[256], outbuffer[256];
s32 *intinbuffer;
@ -99,8 +95,8 @@ class lserver{
int done;
public:
int howmanytimes;
sf::TcpSocket tcpsocket[4];
sf::IpAddress udpaddr[4];
sf::SocketTCP tcpsocket[4];
sf::IPAddress udpaddr[4];
lserver(void);
bool Init(ServerInfoDisplay *);
void Send(void);
@ -109,14 +105,14 @@ public:
class ClientInfoDisplay {
public:
virtual void ConnectStart(const sf::IpAddress& addr) = 0;
virtual void ConnectStart(const sf::IPAddress& addr) = 0;
virtual void Ping() = 0;
virtual void ShowConnect(const int player, const int togo) = 0;
virtual void Connected() = 0;
};
class lclient{
sf::SocketSelector fdset;
sf::Selector<sf::SocketTCP> fdset;
char inbuffer[256], outbuffer[256];
s32 *intinbuffer;
u16 *u16inbuffer;
@ -124,20 +120,19 @@ class lclient{
u16 *u16outbuffer;
int numbytes;
public:
sf::IpAddress serveraddr;
sf::IPAddress serveraddr;
unsigned short serverport;
sf::TcpSocket noblock;
sf::SocketTCP noblock;
int numtransfers;
lclient(void);
bool Init(sf::IpAddress, ClientInfoDisplay *);
bool Init(sf::IPAddress, ClientInfoDisplay *);
void Send(void);
void Recv(void);
void CheckConn(void);
};
typedef struct {
sf::TcpListener listener;
sf::TcpSocket tcpsocket;
sf::SocketTCP tcpsocket;
//sf::SocketUDP udpsocket;
int numslaves;
sf::Thread *thread;
@ -152,7 +147,7 @@ typedef struct {
extern bool gba_joybus_enabled;
extern bool gba_link_enabled;
extern sf::IpAddress joybusHostAddr;
extern sf::IPAddress joybusHostAddr;
extern void JoyBusConnect();
extern void JoyBusShutdown();
extern void JoyBusUpdate(int ticks);

View File

@ -4,20 +4,20 @@
// Currently only for Joybus communications
GBASockClient::GBASockClient(sf::IpAddress _server_addr)
GBASockClient::GBASockClient(sf::IPAddress _server_addr)
{
if (_server_addr == sf::IpAddress::None)
server_addr = sf::IpAddress::LocalHost;
if (!_server_addr.IsValid())
server_addr = sf::IPAddress::LocalHost;
else
server_addr = _server_addr;
client.connect(server_addr, 0xd6ba);
client.Connect(0xd6ba, server_addr);
//client.SetBlocking(false);
}
GBASockClient::~GBASockClient()
{
client.disconnect();
client.Close();
}
void GBASockClient::Send(std::vector<char> data)
@ -25,7 +25,7 @@ void GBASockClient::Send(std::vector<char> data)
char* plain_data = new char[data.size()];
std::copy(data.begin(), data.end(), plain_data);
client.send(plain_data, data.size());
client.Send(plain_data, data.size());
delete[] plain_data;
}
@ -34,7 +34,7 @@ void GBASockClient::Send(std::vector<char> data)
char GBASockClient::ReceiveCmd(char* data_in)
{
std::size_t num_received;
client.receive(data_in, 5, num_received);
client.Receive(data_in, 5, num_received);
return data_in[0];
}

View File

@ -3,16 +3,16 @@
#include <SFML/Network.hpp>
#include "../common/Types.h"
class GBASockClient : public sf::TcpSocket
class GBASockClient : public sf::SocketTCP
{
public:
GBASockClient(sf::IpAddress server_addr);
GBASockClient(sf::IPAddress server_addr);
~GBASockClient();
void Send(std::vector<char> data);
char ReceiveCmd(char* data_in);
private:
sf::IpAddress server_addr;
sf::TcpSocket client;
sf::IPAddress server_addr;
sf::SocketTCP client;
};

View File

@ -91,8 +91,8 @@ public:
sid_t(wxMutex *m, wxCondition *c, wxString *cm, wxString *pm,
bool *d) :
lock(m), sig(c), connmsg(cm), pmsg(pm), done(d) {}
void ShowServerIP(const sf::IpAddress &addr) {
wxString addr_s(addr.toString().c_str(), wxConvLibc);
void ShowServerIP(const sf::IPAddress &addr) {
wxString addr_s(addr.ToString().c_str(), wxConvLibc);
wxString msg;
msg.Printf(_("Server IP address is: %s\n"), addr_s.c_str());
connmsg->append(msg);
@ -155,8 +155,8 @@ public:
cid_t(wxMutex *m, wxCondition *c, wxString *cm, wxString *pm,
bool *d) :
lock(m), sig(c), connmsg(cm), pmsg(pm), done(d) {}
void ConnectStart(const sf::IpAddress &addr) {
wxString addr_s(addr.toString().c_str(), wxConvLibc);
void ConnectStart(const sf::IPAddress &addr) {
wxString addr_s(addr.ToString().c_str(), wxConvLibc);
connmsg->Printf(_("Connecting to %s\n"), addr_s.c_str());
}
void ShowConnect(int player, int togo) {
@ -188,7 +188,7 @@ public:
cid_t* cid = new cid_t(&lock, &sig, &connmsg, &pmsg, &done);
if (!lc.Init(sf::IpAddress(std::string(gopts.link_host.mb_str())), cid)) {
if (!lc.Init(sf::IPAddress(std::string(gopts.link_host.mb_str())), cid)) {
wxLogError(_("Error occurred.\nPlease try again."));
lock.Unlock();
delete cid;
@ -1470,8 +1470,8 @@ public:
if(val.empty())
isv = false;
else {
sf::IpAddress srv = std::string(val.mb_str());
isv = (joybusHostAddr == sf::IpAddress::None);
sf::IPAddress srv = std::string(val.mb_str());
isv = srv.IsValid();
}
if(!isv)
wxMessageBox(_("You must enter a valid host name"),
@ -3098,7 +3098,7 @@ bool MainFrame::InitMore(void)
bool isv = !gopts.joybus_host.empty();
if(isv) {
joybusHostAddr = std::string(gopts.joybus_host.mb_str());
isv = (joybusHostAddr == sf::IpAddress::None);
isv = joybusHostAddr.IsValid();
}
if(!isv) {
wxLogError(_("JoyBus host invalid; disabling"));