Skip to content

Commit

Permalink
Allow setting/clearing game password after game is hosted.
Browse files Browse the repository at this point in the history
Also, if typing password and pressing Enter, actually set the password.
  • Loading branch information
Cyp committed Sep 3, 2012
1 parent 7720aa6 commit 9575cf9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
6 changes: 6 additions & 0 deletions lib/netplay/netplay.cpp
Expand Up @@ -186,7 +186,13 @@ bool NETisCorrectVersion(uint32_t game_version_major, uint32_t game_version_mino
void NETGameLocked( bool flag)
{
NetPlay.GamePassworded = flag;
bool flagChanged = gamestruct.privateGame != flag;
gamestruct.privateGame = flag;
if (allow_joining && NetPlay.isHost && flagChanged)
{
debug(LOG_NET, "Updating game locked status.");
NETregisterServer(WZ_SERVER_UPDATE);
}
NETlogEntry("Password is", SYNC_FLAG, NetPlay.GamePassworded);
debug(LOG_NET, "Passworded game is %s", NetPlay.GamePassworded ? "TRUE" : "FALSE" );
}
Expand Down
91 changes: 42 additions & 49 deletions src/multiint.cpp
Expand Up @@ -1464,18 +1464,14 @@ static void addGameOptions()
widgSetButtonState(psWScreen, MULTIOP_MAP_ICON, WBUT_DISABLE);
}
// password box
if (NetPlay.GamePassworded && ingame.bHostSetup && bHosted)
if (ingame.bHostSetup && NetPlay.bComms)
{
// FIXME: we can't force the state down (it gets reset), so we must handle it this way for now
addMultiEditBox(MULTIOP_OPTIONS, MULTIOP_PASSWORD_EDIT, MCOL0, MROW4, _("Password is already set!"), NetPlay.gamePassword, IMAGE_LOCK_BLUE, IMAGE_LOCK_BLUE, MULTIOP_PASSWORD_BUT);
// force the state down if a locked game
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT, WBUT_LOCK);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_EDIT, WEDBS_DISABLE);
}
else if (ingame.bHostSetup && !bHosted && NetPlay.bComms)
{
// only show this when we are not hosting a game
addMultiEditBox(MULTIOP_OPTIONS, MULTIOP_PASSWORD_EDIT, MCOL0, MROW4, _("Click to set Password"), NetPlay.gamePassword, IMAGE_UNLOCK_BLUE, IMAGE_LOCK_BLUE, MULTIOP_PASSWORD_BUT);
if (NetPlay.GamePassworded)
{
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT, WBUT_CLICKLOCK);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_EDIT, WEDBS_DISABLE);
}
}

// buttons
Expand Down Expand Up @@ -2635,12 +2631,6 @@ static void disableMultiButs(void)
// edit box icons.
widgSetButtonState(psWScreen, MULTIOP_GNAME_ICON, WBUT_DISABLE);
widgSetButtonState(psWScreen, MULTIOP_MAP_ICON, WBUT_DISABLE);
if (NetPlay.GamePassworded)
{
// force the state down if a locked game
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT, WBUT_LOCK);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT, WBUT_DISABLE);
}

// edit boxes
widgSetButtonState(psWScreen,MULTIOP_GNAME,WEDBS_DISABLE);
Expand Down Expand Up @@ -2754,39 +2744,6 @@ static void processMultiopWidgets(UDWORD id)
addMultiRequest(MultiCustomMapsPath, ".wrf", MULTIOP_MAP, current_tech, current_numplayers);
break;

case MULTIOP_PASSWORD_BUT:
{
char game_password[64];
char buf[255];
int32_t result = 0;

result = widgGetButtonState(psWScreen, MULTIOP_PASSWORD_BUT);
debug(LOG_NET, "Password button hit, %d", result);
if (result == 0)
{
sstrcpy(game_password, widgGetString(psWScreen, MULTIOP_PASSWORD_EDIT));
NETsetGamePassword(game_password);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT, WBUT_CLICKLOCK);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_EDIT, WEDBS_DISABLE);
// say password is now required to join games?
ssprintf(buf, _("*** password [%s] is now required! ***"), NetPlay.gamePassword);
addConsoleMessage(buf, DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
NETGameLocked(true);
}
else
{
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT , 0);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_EDIT, 0);
ssprintf(buf, _("*** password is NOT required! ***"));
addConsoleMessage(buf, DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
NETresetGamePassword();
NETGameLocked(false);
break;
}

}
break;

case MULTIOP_MAP_BUT:
loadMapPreview(true);
break;
Expand Down Expand Up @@ -2939,6 +2896,42 @@ static void processMultiopWidgets(UDWORD id)
sendOptions();
}
break;

case MULTIOP_PASSWORD_EDIT:
{
unsigned result = widgGetButtonState(psWScreen, MULTIOP_PASSWORD_BUT);
if (result != 0)
{
break;
}
}
// Continue, do not break, since we just set a password.
case MULTIOP_PASSWORD_BUT:
{
char buf[255];

bool willSet = widgGetButtonState(psWScreen, MULTIOP_PASSWORD_BUT) == 0;
debug(LOG_NET, "Password button hit, %d", (int)willSet);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_BUT, willSet? WBUT_CLICKLOCK : 0);
widgSetButtonState(psWScreen, MULTIOP_PASSWORD_EDIT, willSet? WEDBS_DISABLE : 0);
if (willSet)
{
char game_password[64];
sstrcpy(game_password, widgGetString(psWScreen, MULTIOP_PASSWORD_EDIT));
NETsetGamePassword(game_password);
// say password is now required to join games?
ssprintf(buf, _("*** password [%s] is now required! ***"), NetPlay.gamePassword);
addConsoleMessage(buf, DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
}
else
{
NETresetGamePassword();
ssprintf(buf, _("*** password is NOT required! ***"));
addConsoleMessage(buf, DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
}
NETGameLocked(willSet);
}
break;
}
}

Expand Down

0 comments on commit 9575cf9

Please sign in to comment.