Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/kestasjk/webDiplomacy
Browse files Browse the repository at this point in the history
# Conflicts (all resolved):
#	admin/adminActionsRestricted.php
#	datc/datcGame.php
#	gamecreate.php
#	gamemaster/game.php
#	gamepanel/game.php
#	global/definitions.php
#	halloffame.php
#	lib/time.php
#	locales/English/gamecreate.php
#	objects/game.php
#	register.php
  • Loading branch information
Sleepcap committed Apr 1, 2020
2 parents 5c9705c + 2cb5e06 commit 7382d9d
Show file tree
Hide file tree
Showing 31 changed files with 558 additions and 178 deletions.
52 changes: 46 additions & 6 deletions admin/adminActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class adminActions extends adminActionsForms
),
'banUser' => array(
'name' => 'Ban a user',
'description' => 'Bans a user, setting his games to civil disorder, and removing his points.',
'description' => 'Bans a user, setting their games to civil disorder, and removing their points.',
'params' => array('userID'=>'User ID','reason'=>'Reason'),
),
'unbanUser' => array(
Expand Down Expand Up @@ -204,7 +204,12 @@ class adminActions extends adminActionsForms
'name' => 'Excused Missed Turns - Remove',
'description' => 'Removes 1 excused missed turn for a specific user in a game. If the user(s) do not have excused turns left nothing will happen.',
'params' => array('gameID'=>'Game ID','userID'=>'User ID'),
)
),
'generateRegistrationLink' => array(
'name' => 'Generate Registration Link',
'description' => 'Generate a registration email link for a user having problems making an account.',
'params' => array('email'=>'Registration Email'),
),
);

public function __construct()
Expand Down Expand Up @@ -628,8 +633,13 @@ public function cancelGame(array $params)

if( $Game->phase == 'Diplomacy' or $Game->phase == 'Retreats' or $Game->phase == 'Builds' )
{
list($gameName, $pot, $potType, $varID) = $DB->sql_row("SELECT name, pot, potType, variantID FROM wD_Games WHERE id=".$gameID);
$logInfo = 'Game ID: '.$gameID.' was cancelled. Name: '.$gameName.', Pot: '.$pot.', Pot Type: '.$potType.', VariantID: '.$varID;
$name = addslashes($Game->name);
$pot = $Game->pot;
$potType = $Game->potType;
$varID = $Game->variantID;

$logInfo = 'Game ID: '.$name.' was cancelled. Name: '.$name.', Pot: '.$pot.', Pot Type: '.$potType.', VariantID: '.$varID;

$tabl = $DB->sql_tabl("SELECT countryID, userID, bet, status FROM wD_Members WHERE gameID=".$gameID);
while(list($curCountryID,$curUserID,$curBet,$curStatus) = $DB->tabl_row($tabl))
{
Expand Down Expand Up @@ -726,9 +736,13 @@ public function cancelGame(array $params)
}*/

// Now backup and erase the game from existence, then commit:
list($gameName, $pot, $potType, $varID) = $DB->sql_row("SELECT name, pot, potType, variantID FROM wD_Games WHERE id=".$gameID);
$name = addslashes($Game->name);
$pot = $Game->pot;
$potType = $Game->potType;
$varID = $Game->variantID;

$logInfo = 'Game ID: '.$name.' was cancelled. Name: '.$name.', Pot: '.$pot.', Pot Type: '.$potType.', VariantID: '.$varID;

$logInfo = 'Game ID: '.$gameID.' was cancelled. Name: '.$gameName.', Pot: '.$pot.', Pot Type: '.$potType.', VariantID: '.$varID;
$tabl = $DB->sql_tabl("SELECT countryID, userID, bet, status FROM wD_Members WHERE gameID=".$gameID);

while(list($curCountryID,$curUserID,$curBet,$curStatus) = $DB->tabl_row($tabl))
Expand Down Expand Up @@ -1221,6 +1235,32 @@ public function recalculateUserRR(array $params)

return "This user's RR has been recalculated.";
}

public function generateRegistrationLink(array $params)
{
global $DB;

if (!isset($params['email']))
return "Please enter a valid email.";

$email = $DB->msg_escape($params['email']);

list($emailAlreadyInUse) = $DB->sql_row("SELECT count(1) FROM wD_Users WHERE email = '".$email."'");
if ($emailAlreadyInUse > 0)
{
list($emailUsername) = $DB->sql_row("SELECT username FROM wD_Users WHERE email = '".$email."'");
return "This email is already in use for ".$emailUsername;
}

$thisURL = 'http://'.$_SERVER['SERVER_NAME']."/register.php";
if ($_SERVER['SERVER_NAME'] == '127.0.0.1')
$thisURL = 'http://'.$_SERVER['SERVER_NAME']."/webdiplomacy/register.php";

$emailToken = substr(md5(Config::$secret.$email),0,5).'%7C'.urlencode($email);

return "Please give the user the following link: <br>".$thisURL.'?emailToken='.$emailToken;
}

}

?>
57 changes: 57 additions & 0 deletions admin/adminActionsRestricted.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function __construct()
'description' => 'Takes forum moderator status from the specified user ID.',
'params' => array('userID'=>'Mod User ID'),
),
'changeUsername' => array(
'name' => 'Change username',
'description' => 'Changes user\'s current name to the specified username.',
'params' => array('userID'=>'User ID', 'username'=>'New Username', 'reason'=>'Reason'),
),
'giveBot' => array(
'name' => 'Give bot status',
'description' => 'Gives bot status to the specified user ID.',
Expand Down Expand Up @@ -537,6 +542,58 @@ public function takeForumModerator(array $params)

return l_t('This user had their forum moderator status taken.');
}

public function changeUsername(array $params)
{
global $DB;
global $User;

$userID = (int)$params['userID'];
$newUsername = (string)$params['username'];

if( !isset($params['reason']) || strlen($params['reason'])==0 )
{
return l_t("Could not change username because no reason was given.");
}

$changeReason = $DB->msg_escape($params['reason']);

// check if username exists
list($result) = $DB->sql_row("SELECT username FROM wD_Users WHERE username = '".$newUsername."'");
if (!empty($result))
{
return l_t("This username has already been taken by another user.");
}

// get and store old username and if it exists set new username
list($oldUsername) = $DB->sql_row("SELECT username FROM wD_Users WHERE id = ".$userID);
if (empty($oldUsername))
{
return l_t("User id %s has not been found.", $userID);
}

$time = time();
$changedBy = $User->username;

$DB->sql_put(
'INSERT INTO wD_UsernameHistory (userID, oldUsername, newUsername, date, reason, changedBy)
VALUES ("'.$userID.'", "'.$oldUsername.'", "'.$newUsername.'", "'.$time.'", "'.$changeReason.'", "'.$changedBy.'")'
);
$DB->sql_put("UPDATE wD_Users SET username = '".$newUsername."' WHERE id = '".$userID."' limit 1");

// update new forum on webdip
if (isset(Config::$customForumURL))
{
$newUsernameClean = strtolower($newUsername);

$DB->sql_put(
"UPDATE phpbb_users SET username = '".$newUsername."', username_clean = '".$newUsernameClean."'
WHERE username = '".$oldUsername."' AND webdip_user_id = '".$userID."' limit 1"
);
}

return l_t("This user's username has been changed from %s to %s.",$oldUsername, $newUsername);
}

public function giveBot(array $params)
{
Expand Down
9 changes: 4 additions & 5 deletions botgamecreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@

list($countryCount) = $DB->sql_row("SELECT countryCount FROM wD_VariantInfo WHERE variantID=".$input['variantID']);

if ($input['countryID'] < 0 or $input['countryID'] > 7)
if ($input['countryID'] < 0 or $input['countryID'] > $countryCount)
{
throw new Exception(l_t("%s is an invalid country ID.",(string)$input['countryID']));
}

// Create Game record & object
require_once(l_r('gamemaster/game.php'));
$Game = processGame::create($input['variantID'],$input['name'],'',5,'Unranked',4320,60,'No','Regular','Normal','draw-votes-public',0,4,'MemberVsBots');
$Game = processGame::create($input['variantID'],$input['name'],'',5,'Unranked',4320, 4320, -1, 60,'No','Regular','Normal','draw-votes-public',0,4,'MemberVsBots');

// Prevent temp banned players from making new games.
if ($User->userIsTempBanned())
Expand All @@ -99,10 +99,12 @@

// Create first Member record & object
processMember::create($User->id, 5, $input['countryID']);

//Add Bots
$botNum = $countryCount - 1;
$tabl = $DB->sql_tabl("SELECT id FROM wD_Users WHERE type LIKE '%bot%' LIMIT ".$botNum);
$currCountry = 1;

while (list($botID) = $DB->tabl_row($tabl))
{
if($currCountry == $input['countryID'])
Expand Down Expand Up @@ -173,7 +175,6 @@ function setExtOptions(i){
{
if (in_array($variantID, Config::$apiConfig['variantIDs']))
{

$Variant = libVariant::loadFromVariantName($variantName);
$checkboxes[$Variant->fullName] = '<option value="'.$variantID.'"'.(($first=='')?' selected':'').'>'.$Variant->fullName.'</option>';
if($first=='')
Expand Down Expand Up @@ -213,8 +214,6 @@ function setExtOptions(i){
print '</form>
</div>';



print '</div>';
libHTML::footer();
?>
5 changes: 1 addition & 4 deletions css/darkMode/desktopOnly/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ input[type="text"], input[type="password"], textarea, select {
background-color: #757b81;
border: 1px solid #ccc;
color:rgba(255, 255, 255, 0.8);
cursor: default;
}

input:read-only.toggle-notice {
Expand Down Expand Up @@ -1115,10 +1116,6 @@ input[type=submit].gameCreate:hover {
background-color: #45a049;
}

select option {
background: #777 !important;
}

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
Expand Down
3 changes: 0 additions & 3 deletions css/darkMode/desktopOnly/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
.homeInfoList strong {
font-style:normal;
}
a.current {
color:black !important;
}
div.homeUserContent {
margin-top:15px;
}
Expand Down
4 changes: 0 additions & 4 deletions css/darkMode/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,6 @@ input[type=submit].gameCreate:hover {
background-color: #45a049;
}

select option {
background: #777 !important;
}

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
Expand Down
3 changes: 0 additions & 3 deletions css/darkMode/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
.homeInfoList strong {
font-style:normal;
}
a.current {
color:black !important;
}
div.homeUserContent {
margin-top:15px;
}
Expand Down
4 changes: 4 additions & 0 deletions css/gamepanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
.gamePotType {
font-style:italic;
}

.timestampGames {
font-weight:bold;
}
div.memberBoardHeader {
padding:0 !important;
border:0;
Expand Down
38 changes: 37 additions & 1 deletion gamecreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
$form = $_REQUEST['newGame']; // This makes $form look harmless when it is unsanitized; the parameters must all be sanitized

$input = array();
$required = array('variantID', 'name', 'password', 'passwordcheck', 'bet', 'potType', 'phaseMinutes', 'joinPeriod', 'anon', 'pressType', 'missingPlayerPolicy','drawType','minimumReliabilityRating','excusedMissedTurns'
$required = array('variantID', 'name', 'password', 'passwordcheck', 'bet', 'potType', 'phaseMinutes', 'nextPhaseMinutes', 'phaseSwitchPeriod', 'joinPeriod', 'anon', 'pressType', 'missingPlayerPolicy','drawType','minimumReliabilityRating','excusedMissedTurns'
,'countryID'
,'minPhases'
,'maxTurns'
Expand Down Expand Up @@ -115,6 +115,31 @@
throw new Exception(l_t("The phase value is too large or small; it must be between 5 minutes and 10 days."));
}

$input['nextPhaseMinutes'] = (int)$input['nextPhaseMinutes'];
$input['phaseSwitchPeriod'] = (int)$input['phaseSwitchPeriod'];

// If a game is not live, set the next phase minutes to match the phase.
if ($input['phaseMinutes'] > 60)
{
$input['nextPhaseMinutes'] = $input['phaseMinutes'];
$input['phaseSwitchPeriod'] = -1;
}

if ($input['phaseMinutes'] < 61 and $input['phaseSwitchPeriod'] != -1)
{
// If the next phase minutes is less than 1 day or more than 10 because someone is messing around with the console, default to 2 days if the game is live.
if (($input['nextPhaseMinutes'] < 1440 or $input['nextPhaseMinutes'] > 1440*10))
{
$input['nextPhaseMinutes'] = 2880;
}

// If the phase Switch period is outside the allowed range default it to 3 hours.
if (($input['phaseSwitchPeriod'] > 360 or $input['phaseSwitchPeriod'] < $input['phaseMinutes']))
{
$input['phaseSwitchPeriod'] = 180;
}
}

$input['joinPeriod'] = (int)$input['joinPeriod'];
if ( $input['joinPeriod'] < 5 or $input['joinPeriod'] > 1440*14 )
{
Expand All @@ -124,6 +149,11 @@
$input['anon'] = ( (strtolower($input['anon']) == 'yes') ? 'Yes' : 'No' );

// Force 1 vs 1 variants to be unranked to prevent point farming.
if ( $input['variantID'] == 15 or $input['variantID'] == 23)
{
$input['bet'] = 5;
$input['potType'] = 'Unranked';
}
// if ( $input['variantID'] == 15 )
// {
// $input['bet'] = 5;
Expand Down Expand Up @@ -160,6 +190,7 @@
$input['pressType'] = 'Regular';
}

// Force bot games to be no press and unranked.
if($input['botFill'] == 'Yes')
{
$input['pressType'] = 'NoPress';
Expand All @@ -185,15 +216,18 @@
$input['drawType'] = 'draw-votes-public';
break;
}

$input['minimumReliabilityRating'] = (int)$input['minimumReliabilityRating'];
if ( $input['minimumReliabilityRating'] < 0 or $input['minimumReliabilityRating'] > 100 )
{
throw new Exception(l_t("The reliability rating threshold must range from 0-100"));
}

if ( $input['minimumReliabilityRating'] > $User->reliabilityRating )
{
throw new Exception(l_t("Your reliability rating is %s%%, so you can't create a game which requires players to have a RR of %s%% or greater.",($User->reliabilityRating),$input['minimumReliabilityRating']));
}

$input['excusedMissedTurns'] = (int) $input['excusedMissedTurns'];
if ( $input['excusedMissedTurns'] < 0 || $input['excusedMissedTurns'] > 4 )
{
Expand Down Expand Up @@ -263,6 +297,8 @@
$input['bet'],
$input['potType'],
$input['phaseMinutes'],
$input['nextPhaseMinutes'],
$input['phaseSwitchPeriod'],
$input['joinPeriod'],
$input['anon'],
$input['pressType'],
Expand Down
2 changes: 2 additions & 0 deletions gamemaster/adjudicator/pregame.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ function adjudicate()
$this->assignTerritories();
$this->assignUnits();
$this->assignUnitOccupations();
// Initialize the game's start time at this point.
$Game->initializeStartTime();
}
}

Expand Down
Loading

0 comments on commit 7382d9d

Please sign in to comment.