mirror of
https://github.com/vanilla-wiiu/vanilla.git
synced 2025-01-22 08:11:47 -05:00
allow setting IP
This commit is contained in:
parent
627fa4e82b
commit
45d95cca47
11 changed files with 57 additions and 76 deletions
|
@ -39,9 +39,9 @@ void Backend::init()
|
|||
emit ready();
|
||||
}
|
||||
|
||||
BackendViaLocalRoot::BackendViaLocalRoot(const QString &wirelessInterface, QObject *parent) : Backend(parent)
|
||||
BackendViaLocalRoot::BackendViaLocalRoot(const QHostAddress &udpServer, QObject *parent) : Backend(parent)
|
||||
{
|
||||
m_wirelessInterface = wirelessInterface;
|
||||
m_serverAddress = udpServer;
|
||||
}
|
||||
|
||||
void BackendViaLocalRoot::interrupt()
|
||||
|
@ -56,16 +56,16 @@ void BackendViaLocalRoot::requestIDR()
|
|||
|
||||
void BackendViaLocalRoot::connectToConsole()
|
||||
{
|
||||
QtConcurrent::run(connectInternal, this, m_wirelessInterface);
|
||||
QtConcurrent::run(connectInternal, this, m_serverAddress);
|
||||
}
|
||||
|
||||
int BackendViaLocalRoot::connectInternal(BackendViaLocalRoot *instance, const QString &intf)
|
||||
int BackendViaLocalRoot::connectInternal(BackendViaLocalRoot *instance, const QHostAddress &server)
|
||||
{
|
||||
QByteArray wirelessInterfaceC = intf.toUtf8();
|
||||
return vanilla_start(vanillaEventHandler, instance);
|
||||
//return vanilla_connect_to_console(wirelessInterfaceC.constData(), vanillaEventHandler, instance);
|
||||
// printf("TEMPORARILY STUBBED\n");
|
||||
// return 0;
|
||||
if (server.isNull()) {
|
||||
return vanilla_start(vanillaEventHandler, instance);
|
||||
} else {
|
||||
return vanilla_start_udp(vanillaEventHandler, instance, server.toIPv4Address());
|
||||
}
|
||||
}
|
||||
|
||||
void BackendViaLocalRoot::updateTouch(int x, int y)
|
||||
|
@ -88,21 +88,6 @@ void BackendViaLocalRoot::setBatteryStatus(int status)
|
|||
vanilla_set_battery_status(status);
|
||||
}
|
||||
|
||||
void BackendViaLocalRoot::sync(uint16_t code)
|
||||
{
|
||||
QFutureWatcher<int> *watcher = new QFutureWatcher<int>(this);
|
||||
connect(watcher, &QFutureWatcher<int>::finished, this, &BackendViaLocalRoot::syncFutureCompleted);
|
||||
watcher->setFuture(QtConcurrent::run(syncInternal, m_wirelessInterface, code));
|
||||
}
|
||||
|
||||
int BackendViaLocalRoot::syncInternal(const QString &intf, uint16_t code)
|
||||
{
|
||||
QByteArray wirelessInterfaceC = intf.toUtf8();
|
||||
//return vanilla_sync_with_console(wirelessInterfaceC.constData(), code);
|
||||
printf("TEMPORARILY STUBBED\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BackendViaLocalRoot::syncFutureCompleted()
|
||||
{
|
||||
QFutureWatcher<int> *watcher = static_cast<QFutureWatcher<int>*>(sender());
|
||||
|
|
|
@ -67,7 +67,6 @@ signals:
|
|||
public slots:
|
||||
// These slots must be called with Qt::QueuedConnection to start the event loops in the backend's thread
|
||||
virtual void init();
|
||||
virtual void sync(uint16_t code) = 0;
|
||||
virtual void connectToConsole() = 0;
|
||||
|
||||
};
|
||||
|
@ -76,7 +75,7 @@ class BackendViaLocalRoot : public Backend
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BackendViaLocalRoot(const QString &wirelessInterface, QObject *parent = nullptr);
|
||||
BackendViaLocalRoot(const QHostAddress &serverAddress, QObject *parent = nullptr);
|
||||
|
||||
virtual void interrupt() override;
|
||||
virtual void updateTouch(int x, int y) override;
|
||||
|
@ -86,13 +85,11 @@ public:
|
|||
virtual void setBatteryStatus(int status) override;
|
||||
|
||||
public slots:
|
||||
virtual void sync(uint16_t code) override;
|
||||
virtual void connectToConsole() override;
|
||||
|
||||
private:
|
||||
static int syncInternal(const QString &intf, uint16_t code);
|
||||
static int connectInternal(BackendViaLocalRoot *instance, const QString &intf);
|
||||
QString m_wirelessInterface;
|
||||
static int connectInternal(BackendViaLocalRoot *instance, const QHostAddress &serverAddress);
|
||||
QHostAddress m_serverAddress;
|
||||
|
||||
private slots:
|
||||
void syncFutureCompleted();
|
||||
|
|
|
@ -348,10 +348,10 @@ void MainWindow::initBackend(T func)
|
|||
d->open();
|
||||
|
||||
QString localWirelessIntf = m_wirelessInterfaceComboBox->currentData().toString();
|
||||
if (0 && localWirelessIntf.isEmpty()) {
|
||||
if (localWirelessIntf.isEmpty()) {
|
||||
UdpAddressDialog udpDiag(this);
|
||||
if (udpDiag.exec() == QDialog::Accepted) {
|
||||
// m_backend = new BackendViaSocket(udpDiag.acceptedAddress(), udpDiag.acceptedPort());
|
||||
m_backend = new BackendViaLocalRoot(udpDiag.acceptedAddress());
|
||||
} else {
|
||||
d->deleteLater();
|
||||
closeBackend();
|
||||
|
@ -359,7 +359,7 @@ void MainWindow::initBackend(T func)
|
|||
}
|
||||
} else {
|
||||
// If root, use lib locally
|
||||
m_backend = new BackendViaLocalRoot(localWirelessIntf);
|
||||
m_backend = new BackendViaLocalRoot(QHostAddress());
|
||||
}
|
||||
|
||||
connect(m_backend, &Backend::closed, d, &BackendInitDialog::deleteLater);
|
||||
|
|
|
@ -12,7 +12,7 @@ UdpAddressDialog::UdpAddressDialog(QWidget *parent) : QDialog(parent)
|
|||
layout->addWidget(new QLabel(tr("<html><center><p><b>UDP Server Connection</b></p><p>Connect to a separate device handling the connection to the console.</p></center></html>")));
|
||||
|
||||
m_addressLine = new QLineEdit(this);
|
||||
m_addressLine->setPlaceholderText(QStringLiteral("127.0.0.1:10200"));
|
||||
m_addressLine->setPlaceholderText(QStringLiteral("127.0.0.1"));
|
||||
layout->addWidget(m_addressLine);
|
||||
|
||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||||
|
@ -30,27 +30,13 @@ void UdpAddressDialog::done(int r)
|
|||
return;
|
||||
}
|
||||
|
||||
QStringList addressSplit = m_addressLine->text().split(':');
|
||||
if (addressSplit.size() != 2) {
|
||||
QMessageBox::critical(this, tr("Invalid Address"), tr("Invalid format, must be entered in the form of <address>:<port> (e.g. 127.0.0.1:10200)."));
|
||||
return;
|
||||
}
|
||||
|
||||
QHostAddress addressPortion = QHostAddress(addressSplit.at(0));
|
||||
QHostAddress addressPortion = QHostAddress(m_addressLine->text());
|
||||
if (addressPortion.isNull()) {
|
||||
QMessageBox::critical(this, tr("Invalid Address"), tr("Address is invalid."));
|
||||
return;
|
||||
}
|
||||
|
||||
bool portOk;
|
||||
quint16 portPortion = addressSplit.at(1).toUShort(&portOk);
|
||||
if (!portOk) {
|
||||
QMessageBox::critical(this, tr("Invalid Address"), tr("Port is invalid."));
|
||||
return;
|
||||
}
|
||||
|
||||
m_acceptedAddress = addressPortion;
|
||||
m_acceptedPort = portPortion;
|
||||
}
|
||||
|
||||
QDialog::done(r);
|
||||
|
|
|
@ -12,7 +12,6 @@ public:
|
|||
UdpAddressDialog(QWidget *parent = nullptr);
|
||||
|
||||
inline const QHostAddress &acceptedAddress() const { return m_acceptedAddress; }
|
||||
inline const quint16 &acceptedPort() const { return m_acceptedPort; }
|
||||
|
||||
public slots:
|
||||
virtual void done(int r) override;
|
||||
|
@ -20,7 +19,6 @@ public slots:
|
|||
private:
|
||||
QLineEdit *m_addressLine;
|
||||
QHostAddress m_acceptedAddress;
|
||||
quint16 m_acceptedPort;
|
||||
};
|
||||
|
||||
#endif // UDP_ADDRESS_DIALOG
|
|
@ -19,6 +19,13 @@
|
|||
#include "util.h"
|
||||
|
||||
static const uint32_t STOP_CODE = 0xCAFEBABE;
|
||||
static uint32_t SERVER_ADDRESS = 0;
|
||||
|
||||
uint16_t PORT_MSG = 50110;
|
||||
uint16_t PORT_VID = 50120;
|
||||
uint16_t PORT_AUD = 50121;
|
||||
uint16_t PORT_HID = 50122;
|
||||
uint16_t PORT_CMD = 50123;
|
||||
|
||||
unsigned int reverse_bits(unsigned int b, int bit_count)
|
||||
{
|
||||
|
@ -35,8 +42,12 @@ void send_to_console(int fd, const void *data, size_t data_size, int port)
|
|||
{
|
||||
struct sockaddr_in address;
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = inet_addr("127.0.0.1"); // inet_addr("192.168.1.10");
|
||||
address.sin_addr.s_addr = SERVER_ADDRESS;
|
||||
address.sin_port = htons((uint16_t) (port - 100));
|
||||
|
||||
char ip[20];
|
||||
inet_ntop(AF_INET, &address.sin_addr, ip, sizeof(ip));
|
||||
|
||||
ssize_t sent = sendto(fd, data, data_size, 0, (const struct sockaddr *) &address, sizeof(address));
|
||||
if (sent == -1) {
|
||||
print_info("Failed to send to Wii U socket: fd - %d; port - %d", fd, port);
|
||||
|
@ -45,16 +56,12 @@ void send_to_console(int fd, const void *data, size_t data_size, int port)
|
|||
|
||||
int create_socket(int *socket_out, uint16_t port)
|
||||
{
|
||||
// TODO: Limit these sockets to one interface?
|
||||
|
||||
struct sockaddr_in address;
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
address.sin_port = htons(port);
|
||||
(*socket_out) = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
//setsockopt((*socket_out), SOL_SOCKET, SO_RCVTIMEO)
|
||||
|
||||
if (bind((*socket_out), (const struct sockaddr *) &address, sizeof(address)) == -1) {
|
||||
print_info("FAILED TO BIND PORT %u: %i", port, errno);
|
||||
return 0;
|
||||
|
@ -73,8 +80,19 @@ void send_stop_code(int from_socket, in_port_t port)
|
|||
sendto(from_socket, &STOP_CODE, sizeof(STOP_CODE), 0, (struct sockaddr *)&address, sizeof(address));
|
||||
}
|
||||
|
||||
int main_loop(vanilla_event_handler_t event_handler, void *context)
|
||||
int connect_as_gamepad_internal(vanilla_event_handler_t event_handler, void *context, uint32_t server_address)
|
||||
{
|
||||
if (server_address == 0) {
|
||||
SERVER_ADDRESS = inet_addr("192.168.1.10");
|
||||
} else {
|
||||
SERVER_ADDRESS = htonl(server_address);
|
||||
PORT_MSG += 200;
|
||||
PORT_VID += 200;
|
||||
PORT_AUD += 200;
|
||||
PORT_HID += 200;
|
||||
PORT_CMD += 200;
|
||||
}
|
||||
|
||||
struct gamepad_thread_context info;
|
||||
info.event_handler = event_handler;
|
||||
info.context = context;
|
||||
|
@ -95,8 +113,6 @@ int main_loop(vanilla_event_handler_t event_handler, void *context)
|
|||
pthread_create(&input_thread, NULL, listen_input, &info);
|
||||
pthread_create(&cmd_thread, NULL, listen_command, &info);
|
||||
|
||||
print_info("ready!");
|
||||
|
||||
while (1) {
|
||||
usleep(250 * 1000);
|
||||
if (is_interrupted()) {
|
||||
|
@ -134,11 +150,6 @@ exit:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int connect_as_gamepad_internal(vanilla_event_handler_t event_handler, void *context)
|
||||
{
|
||||
return main_loop(event_handler, context);
|
||||
}
|
||||
|
||||
int is_stop_code(const char *data, size_t data_length)
|
||||
{
|
||||
return (data_length == sizeof(STOP_CODE) && !memcmp(data, &STOP_CODE, sizeof(STOP_CODE)));
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#ifndef VANILLA_GAMEPAD_H
|
||||
#define VANILLA_GAMEPAD_H
|
||||
|
||||
// #include "ports.h"
|
||||
#include "vanilla.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint16_t PORT_MSG = 50310;
|
||||
static const uint16_t PORT_VID = 50320;
|
||||
static const uint16_t PORT_AUD = 50321;
|
||||
static const uint16_t PORT_HID = 50322;
|
||||
static const uint16_t PORT_CMD = 50323;
|
||||
extern uint16_t PORT_MSG;
|
||||
extern uint16_t PORT_VID;
|
||||
extern uint16_t PORT_AUD;
|
||||
extern uint16_t PORT_HID;
|
||||
extern uint16_t PORT_CMD;
|
||||
|
||||
struct wpa_ctrl;
|
||||
|
||||
|
@ -26,7 +25,7 @@ struct gamepad_thread_context
|
|||
int socket_cmd;
|
||||
};
|
||||
|
||||
int connect_as_gamepad_internal(vanilla_event_handler_t event_handler, void *context);
|
||||
int connect_as_gamepad_internal(vanilla_event_handler_t event_handler, void *context, uint32_t server_address);
|
||||
unsigned int reverse_bits(unsigned int b, int bit_count);
|
||||
void send_to_console(int fd, const void *data, size_t data_size, int port);
|
||||
int is_stop_code(const char *data, size_t data_length);
|
||||
|
|
|
@ -14,7 +14,12 @@
|
|||
|
||||
int vanilla_start(vanilla_event_handler_t event_handler, void *context)
|
||||
{
|
||||
return connect_as_gamepad_internal(event_handler, context);
|
||||
return connect_as_gamepad_internal(event_handler, context, 0);
|
||||
}
|
||||
|
||||
int vanilla_start_udp(vanilla_event_handler_t event_handler, void *context, uint32_t server_address)
|
||||
{
|
||||
return connect_as_gamepad_internal(event_handler, context, server_address);
|
||||
}
|
||||
|
||||
void vanilla_stop()
|
||||
|
|
|
@ -94,6 +94,7 @@ typedef void (*vanilla_event_handler_t)(void *context, int event_type, const cha
|
|||
* Start listening for gamepad commands
|
||||
*/
|
||||
int vanilla_start(vanilla_event_handler_t event_handler, void *context);
|
||||
int vanilla_start_udp(vanilla_event_handler_t event_handler, void *context, uint32_t server_address);
|
||||
|
||||
/**
|
||||
* Attempt to stop the current action
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
#include <unistd.h>
|
||||
#include <wpa_ctrl.h>
|
||||
|
||||
#include "../../lib/gamepad/ports.h"
|
||||
|
||||
#include "ports.h"
|
||||
#include "status.h"
|
||||
#include "util.h"
|
||||
#include "vanilla.h"
|
||||
|
@ -559,7 +558,7 @@ int call_ip(const char **argv)
|
|||
return VANILLA_SUCCESS;
|
||||
}
|
||||
|
||||
int connect_as_gamepad_internal(struct wpa_ctrl *ctrl, const char *wireless_interface)
|
||||
int do_connect(struct wpa_ctrl *ctrl, const char *wireless_interface)
|
||||
{
|
||||
while (1) {
|
||||
while (!wpa_ctrl_pending(ctrl)) {
|
||||
|
@ -821,7 +820,7 @@ int thunk_to_sync(struct wpa_ctrl *ctrl, void *data)
|
|||
int thunk_to_connect(struct wpa_ctrl *ctrl, void *data)
|
||||
{
|
||||
struct connect_args *args = (struct connect_args *) data;
|
||||
return connect_as_gamepad_internal(ctrl, args->wireless_interface);
|
||||
return do_connect(ctrl, args->wireless_interface);
|
||||
}
|
||||
|
||||
int vanilla_sync_with_console(const char *wireless_interface, uint16_t code)
|
||||
|
|
Loading…
Reference in a new issue