Handle network settings in the menu

This commit is contained in:
simon.kagstrom 2009-03-01 08:27:53 +00:00
parent fa543ac596
commit e65ac515f7
4 changed files with 40 additions and 15 deletions

View File

@ -72,7 +72,7 @@ void C64::c64_ctor1(void)
this->virtual_keyboard = new VirtualKeyboard(real_screen, this->menu_font);
strncpy(this->server_hostname, "localhost",
strncpy(this->server_hostname, "c64-network.game-host.org",
sizeof(this->server_hostname));
this->server_port = 46214;
this->network_connection_type = NONE;
@ -308,31 +308,43 @@ void C64::networking_menu(Prefs *np)
do
{
char buf[2][255];
char buf[3][255];
const char *network_client_messages[] = {
"Listen for connections",/* 0 */
buf[0], /* 1 */
buf[1], /* 2 */
"Connect to remote", /* 3 */
buf[0], /* 0 */
buf[1], /* 1 */
buf[2], /* 2 */
"Connect as server", /* 3 */
"Connect as client", /* 4 */
NULL,
};
snprintf(buf[0], 255, "Remote hostname (now %s)",
snprintf(buf[0], 255, "Set username (%s)",
np->NetworkName);
snprintf(buf[1], 255, "Server hostname (%s)",
this->server_hostname);
snprintf(buf[1], 255, "Port (now %d)",
snprintf(buf[2], 255, "Port (%d)",
this->server_port);
opt = menu_select(network_client_messages, NULL);
if (opt == 1 || opt == 2)
if (opt >= 0 && opt <= 2)
{
const char *m = this->virtual_keyboard->get_string();
if (m && opt == 1)
if (m)
{
if (opt == 0)
{
memset(np->NetworkName, 0,
sizeof(np->NetworkName));
strncpy(np->NetworkName, m,
sizeof(np->NetworkName));
} else if (opt == 1)
strncpy(this->server_hostname, m,
sizeof(this->server_hostname));
if (m && opt == 2)
if (opt == 2)
this->server_port = atoi(m);
}
}
else if (opt == 0) {
this->peer = new Network(this->server_hostname,
this->server_port, true);

View File

@ -21,6 +21,7 @@
#include "sysdeps.h"
#include "Network.h"
#include "Display.h"
#include "Prefs.h"
#include "menu.h"
#define N_SQUARES_W 16
@ -753,7 +754,7 @@ bool Network::ConnectToBroker()
pi->is_master = this->is_master;
pi->key = random() % 0xffff;
strcpy((char*)pi->name, "Mr vobb");
strcpy((char*)pi->name, ThePrefs.NetworkName);
this->AddNetworkUpdate(ud);
out = this->SendUpdate();
this->ResetNetworkUpdate();

View File

@ -102,6 +102,8 @@ Prefs::Prefs()
this->DisplayOption = 0;
this->MsPerFrame = 28;
#endif
this->NetworkKey = random() % 0xffff;
snprintf(this->NetworkName, 32, "Unset.%d", this->NetworkKey);
}
@ -178,6 +180,8 @@ bool Prefs::operator==(const Prefs &rhs) const
&& this->DisplayOption == rhs.DisplayOption
&& this->MsPerFrame == rhs.MsPerFrame
#endif
&& this->NetworkKey == rhs.NetworkKey
&& strcmp(this->NetworkName, rhs.NetworkName) == 0
);
}
@ -359,6 +363,10 @@ void Prefs::Load(char *filename)
DisplayOption = atoi(value);
else if (!strcmp(keyword, "MsPerFrame"))
MsPerFrame = atoi(value);
else if (!strcmp(keyword, "NetworkKey"))
NetworkKey = atoi(value);
else if (!strcmp(keyword, "NetworkName"))
strcpy(NetworkName, value);
#endif
}
}
@ -450,6 +458,8 @@ bool Prefs::Save(char *filename)
fprintf(file, "DisplayOption = %d\n", DisplayOption);
fprintf(file, "MsPerFrame = %d\n", MsPerFrame);
fprintf(file, "NetworkKey = %d\n", NetworkKey);
fprintf(file, "NetworkName = %s\n", NetworkName);
#endif
fclose(file);
ThePrefsOnDisk = *this;

View File

@ -153,6 +153,8 @@ private:
int DisplayOption;
uint32 MsPerFrame;
#endif
char NetworkName[32];
int NetworkKey;
};