Skip to content

Commit 612f803

Browse files
SonickidnextgenSonickidnextgen
authored andcommitted
Fixed a number of configuration problems.
1 parent 93c8fb9 commit 612f803

File tree

6 files changed

+129
-78
lines changed

6 files changed

+129
-78
lines changed

IOSync/src/devices/native/winnt/Real_XInput_Wrapper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,16 @@ namespace REAL_XINPUT
236236
{
237237
#ifdef DEBUG_XINPUT_CALLS
238238
cout << "XInputGetState(" << dwUserIndex << ", " << pState << ")" << endl;
239-
cout << "_XInputGetState: " << _XInputGetState << endl;
240239
#endif
241240

242241
if (_XInputGetState != nullptr)
243242
{
244243
if (shouldFixJumps())
245244
{
246-
#ifdef DEBUG_XINPUT_CALLS
247-
cout << "Jump fixing..." << endl;
248-
#endif
249-
250245
auto entryIterator = jumpStates.find((LPVOID)_XInputGetState);
251246

252247
if (entryIterator != jumpStates.end())
253248
{
254-
#ifdef DEBUG_XINPUT_CALLS
255-
cout << "__XInputGetState? - " << entryIterator->first << endl;
256-
#endif
257-
258249
jumpEntry entry = *entryIterator;
259250

260251
swapJumps(entry);

IOSync/src/iosync.cpp

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace iosync
4545
//ShowWindow(windowInstance, OSInfo.nCmdShow);
4646
UpdateWindow(windowInstance);
4747
#endif
48-
48+
4949
return windowInstance;
5050
}
5151

@@ -1252,8 +1252,13 @@ namespace iosync
12521252
}
12531253
}
12541254

1255-
// Read the username specified.
1256-
username = networking[NETWORK_USERNAME];
1255+
auto usernameIterator = networking.find(NETWORK_USERNAME);
1256+
1257+
if (usernameIterator != networking.end())
1258+
{
1259+
// Read the username specified.
1260+
username = usernameIterator->second;
1261+
}
12571262
}
12581263
else
12591264
{
@@ -1376,7 +1381,7 @@ namespace iosync
13761381
}
13771382
}
13781383

1379-
if (username.length() > 0)
1384+
if (!username.empty())
13801385
networking[NETWORK_USERNAME] = username;
13811386

13821387
// Windows-specific:
@@ -1835,24 +1840,49 @@ namespace iosync
18351840
switch (configuration.mode)
18361841
{
18371842
case MODE_CLIENT:
1838-
// Check if a proper address was specified:
1839-
if (address::addressSet(configuration.remoteAddress.IP))
1843+
do
18401844
{
1841-
return execute(configuration.username, configuration.remoteAddress.IP, configuration.remoteAddress.port);
1842-
}
1843-
else
1844-
{
1845-
bool hostAnyway;
1845+
// Check if a proper address was specified:
1846+
if (address::addressSet(configuration.remoteAddress.IP))
1847+
{
1848+
return execute((configuration.username.empty()) ? DEFAULT_PLAYER_NAME : configuration.username, configuration.remoteAddress.IP, configuration.remoteAddress.port);
1849+
}
1850+
else
1851+
{
1852+
bool hostAnyway;
18461853

1847-
// Check if we should move into the next routine or not:
1848-
cout << "Invalid address specified: Would you like to host instead? (Port: ";
1849-
cout << configuration.remoteAddress.port << ", Y/N): "; hostAnyway = userBoolean(); // cout << endl;
1854+
cout << "Invalid address specified: Would you like to supply a new address? (Y/N): "; hostAnyway = !userBoolean(); // cout << endl;
18501855

1851-
if (!hostAnyway)
1852-
{
1853-
return -1;
1856+
if (!hostAnyway)
1857+
{
1858+
// Request a new address from the user.
1859+
requestAddress(configuration.remoteAddress);
1860+
1861+
// Check if we have a username:
1862+
if (configuration.username.empty())
1863+
{
1864+
cout << "Please supply a username: "; wcin >> configuration.username; // cout << endl;
1865+
}
1866+
}
1867+
else
1868+
{
1869+
// Check if we should move into the next routine or not:
1870+
cout << "Would you like to host instead? (Port: ";
1871+
cout << configuration.remoteAddress.port << ", Y/N): "; hostAnyway = userBoolean(); // cout << endl;
1872+
1873+
if (!hostAnyway)
1874+
{
1875+
// Tell the user that the program failed to execute.
1876+
return -1;
1877+
}
1878+
else
1879+
{
1880+
// Break the endless loop, then move into the next case.
1881+
break;
1882+
}
1883+
}
18541884
}
1855-
}
1885+
} while(true);
18561886
case MODE_SERVER:
18571887
return execute(configuration.remoteAddress.port);
18581888
}
@@ -1881,32 +1911,13 @@ namespace iosync
18811911
{
18821912
case MODE_CLIENT:
18831913
#ifndef IOSYNC_FAST_TESTMODE
1884-
configuration.remoteAddress.IP = "127.0.0.1";
1914+
//configuration.remoteAddress.IP = "127.0.0.1";
18851915
configuration.username = DEFAULT_PLAYER_NAME;
18861916

1887-
{
1888-
string::size_type separatorPosition;
1889-
1890-
cout << "Please supply a hostname: "; cin >> configuration.remoteAddress.IP; // cout << endl;
1917+
// Request an address from the user.
1918+
requestAddress(configuration.remoteAddress);
18911919

1892-
separatorPosition = configuration.remoteAddress.IP.find(networking::ADDRESS_SEPARATOR);
1893-
1894-
if (separatorPosition != string::npos && separatorPosition < configuration.remoteAddress.IP.length())
1895-
{
1896-
configuration.remoteAddress.port = portFromString(configuration.remoteAddress.IP.substr(separatorPosition+1));
1897-
1898-
configuration.remoteAddress.IP = configuration.remoteAddress.IP.substr(0, separatorPosition);
1899-
}
1900-
else
1901-
{
1902-
string portStr;
1903-
1904-
cout << "Please supply a remote-port: ";
1905-
configuration.remoteAddress.port = portFromInput(cin); // cout << endl;
1906-
}
1907-
1908-
cout << "Please enter a username (No spaces): "; wcin >> configuration.username; // cout << endl;
1909-
}
1920+
cout << "Please enter a username (No spaces): "; wcin >> configuration.username; // cout << endl;
19101921
#endif
19111922

19121923
if (logChoices)
@@ -1920,8 +1931,7 @@ namespace iosync
19201931
case MODE_SERVER:
19211932
{
19221933
#ifndef IOSYNC_FAST_TESTMODE
1923-
cout << "Please enter a port to host with: ";
1924-
configuration.remoteAddress.port = portFromInput(cin); // cout << endl;
1934+
configuration.remoteAddress.port = requestPort(cin); // cout << endl;
19251935
#endif
19261936

19271937
#ifndef IOSYNC_FAST_TESTMODE_SINGLE_INPUT

IOSync/src/iosync.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ namespace iosync
892892
return DEFAULT_PORT;
893893
}
894894

895-
static inline nativePort portFromInput(istream& is)
895+
static inline nativePort portFromInput(istream& is=cin)
896896
{
897897
string portStr;
898898

@@ -901,6 +901,39 @@ namespace iosync
901901
return portFromString(portStr);
902902
}
903903

904+
// The return-value of this command follows the behavior of the 'representativeAddress' structure's 'parse' command.
905+
static inline bool addressFromInput(representativeAddress& address, istream& is = cin, addressPort default_port=DEFAULT_PORT)
906+
{
907+
string addr_str;
908+
909+
is >> addr_str;
910+
911+
return address.parse(addr_str, default_port);
912+
}
913+
914+
// This command accepts input from the user, then mutates the remote-address using that data.
915+
static inline void requestAddress(representativeAddress& remoteAddress, istream& is=cin, ostream& os=cout, addressPort default_port=DEFAULT_PORT)
916+
{
917+
do
918+
{
919+
os << "Please supply an address: ";
920+
921+
if (!addressFromInput(remoteAddress, is, default_port))
922+
{
923+
remoteAddress.port = requestPort(is, os);
924+
}
925+
} while (remoteAddress.IP.empty());
926+
927+
return;
928+
}
929+
930+
static inline nativePort requestPort(istream& is=cin, ostream& os=cout)
931+
{
932+
os << "Please supply a port: ";
933+
934+
return portFromInput(is);
935+
}
936+
904937
#ifdef PLATFORM_WINDOWS
905938
static DWORD __winnt__getPIDW(wstring entry);
906939
#endif

IOSync/src/networking/address.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace iosync
2424
// Functions:
2525
bool address::addressSet(string IP)
2626
{
27-
return (IP.length() > 0);
27+
return (!IP.empty());
2828
}
2929

3030
bool address::addressSet(QSOCK_UINT32_LONG IP)

IOSync/src/networking/address.h

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,41 @@ namespace iosync
5656
void writeTo(QSocket& socket);
5757

5858
// Other:
59+
60+
// The return value of this command specifies if both a port, and an IP address/hostname was parsed.
5961
template <typename characterType=char, typename characterTraits=char_traits<characterType>, typename strAlloc=allocator<characterType>>
60-
inline void parse(const basic_string<characterType, characterTraits, strAlloc>& input, addressPort default_port)
62+
inline bool parse(const basic_string<characterType, characterTraits, strAlloc>& input, addressPort default_port)
6163
{
6264
auto addressDivider = input.find(ADDRESS_SEPARATOR);
6365

6466
// Ensure we have a separator.
6567
if (addressDivider != basic_string<characterType, characterTraits, strAlloc>::npos)
6668
{
6769
IP = QSocket::StringToIntIP(quickLib::INI::abstractStringToDefault(input.substr(0, addressDivider)));
68-
port = stoi(input.substr(addressDivider+1));
6970

70-
if (port == 0)
71-
port = default_port;
71+
try
72+
{
73+
port = stoi(input.substr(addressDivider+1));
74+
75+
if (port == 0)
76+
port = default_port;
77+
78+
return true;
79+
}
80+
catch (invalid_argument&)
81+
{
82+
//port = 0;
83+
}
7284
}
7385
else
7486
{
7587
IP = QSocket::nonNativeToNativeIP(quickLib::INI::abstractStringToDefault(input));
76-
port = default_port;
7788
}
7889

79-
return;
90+
port = default_port;
91+
92+
// Return the default response.
93+
return false;
8094
}
8195

8296
template <typename characterType=char, typename characterTraits=char_traits<characterType>, typename strAlloc=allocator<characterType>>
@@ -140,27 +154,40 @@ namespace iosync
140154
// Methods:
141155
bool isSet() const;
142156

157+
// The return value of this command specifies if both a port, and an IP address/hostname was parsed.
143158
template <typename characterType=char, typename characterTraits=char_traits<characterType>, typename strAlloc=allocator<characterType>>
144-
inline void parse(const basic_string<characterType, characterTraits, strAlloc>& input, addressPort default_port)
159+
inline bool parse(const basic_string<characterType, characterTraits, strAlloc>& input, addressPort default_port)
145160
{
146161
auto addressDivider = input.find(ADDRESS_SEPARATOR);
147162

148163
// Ensure we have a separator.
149164
if (addressDivider != basic_string<characterType, characterTraits, strAlloc>::npos)
150165
{
151166
IP = quickLib::INI::abstractStringToDefault(input.substr(0, addressDivider));
152-
port = stoi(input.substr(addressDivider+1));
153167

154-
if (port == 0)
155-
port = default_port;
168+
try
169+
{
170+
port = stoi(input.substr(addressDivider+1));
171+
172+
if (port == 0)
173+
port = default_port;
174+
175+
return true;
176+
}
177+
catch (invalid_argument&)
178+
{
179+
//port = 0;
180+
}
156181
}
157182
else
158183
{
159184
IP = quickLib::INI::abstractStringToDefault(input);
160-
port = default_port;
161185
}
162186

163-
return;
187+
port = default_port;
188+
189+
// Return the default response.
190+
return false;
164191
}
165192

166193
template <typename characterType=char, typename characterTraits=char_traits<characterType>, typename strAlloc=allocator<characterType>>
@@ -169,9 +196,9 @@ namespace iosync
169196
basic_stringstream<characterType, characterTraits, strAlloc> ss;
170197
basic_string<characterType, characterTraits, strAlloc> str;
171198

172-
quickLib::INI::correctString(IP + ADDRESS_SEPARATOR, str);
199+
quickLib::INI::correctString(IP, str);
173200

174-
ss << str << port;
201+
ss << str << ADDRESS_SEPARATOR << port;
175202

176203
out_str = ss.str();
177204

XInput_Injection_DLL/settings.h

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)