testing of the clanfights! Now the basic functionality is tested in several ways!

main
hecht 13 years ago
parent 8157bfb810
commit a322cc273f

@ -21,9 +21,10 @@ function calculateArenaData($owner_id, $char_1, $char_2, $factor){
$arena['steh'] = 1000000;
$arena['sitz'] = 1000000;
$arena['loge'] = 1000000;
} else {
$arena = mysql_fetch_assoc(mysql_query('SELECT * FROM arena WHERE besitzer = '.$owner_id));
}
$arena = mysql_fetch_assoc(mysql_query('SELECT * FROM arena WHERE besitzer = '.$owner_id));
$wert_char1 = max(0.75,min(1.25,$char_1['siege']/($char_1['niederlagen'] + 0.01))) * getPowerLevelWithBuffs($char_1['id']);
$wert_char2 = max(0.75,min(1.25,$char_2['siege']/($char_2['niederlagen'] + 0.01))) * getPowerLevelWithBuffs($char_2['id']);
// Neue Kalkulation :)

@ -13,13 +13,15 @@ defineIfNotDefined('CLANKAMPF', 2);
function getCharAttackSet($char_id, $type) {
$qry = null;
$set = array();
// default values (in case the data is not or partially set)
$set = array(1 => 0,2 => 0,3 => 0,4 => 0,5 => 0,6 => 0,7 => 0,8 => 0,9 => 0,10 => 0);
if(is_numeric($char_id)) {
$test = 'SELECT Attack_ID,Round FROM attackenset WHERE Char_ID = '.$char_id.' AND Type = '.$type;
$qry = mysql_query($test);
}
$i = 0;
while ($result = mysql_fetch_assoc($qry)) {
$set[$result['round']] = $result['attack_id'];

@ -8,6 +8,7 @@
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/defines.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/clan.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/messagefunctions.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/attackenset.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/arena.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf_wrapper.inc.php');
@ -35,7 +36,7 @@ $GLOBALS['clan_challenge_buffered_instances'] = array ();
* @param int $clanid the id of the clan to challenge
* @param int $validTime the amount of hours that the challenge is valid
*/
function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $validTime = 24) {
function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGHT, $validTime = 24) {
$clan = getClan($user['clan']);
$oclan = getClan($clanid);
@ -50,6 +51,10 @@ function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $
return 'Nur der Leader, bzw. der Co-Leader kann andere Clans herausfordern!!';
}
if($clan['id'] == $oclan['id']) {
return 'Du kannst deinen eigenen Clan nicht herausfordern!!';
}
if(isClanLocked($user['clan']) || isClanLocked($clanid)) {
// okay we cannot accept the challenge so make it inactive!
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE clan_challenge_id = ' .$clan_challenge_id);
@ -67,8 +72,8 @@ function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $
// okay we have both semaphores :)
$clan_challenges_my_clan = getOpenChallengesRequestCount($user['clan']);
$clan_challenges_oth_clan = getOpenChallengesRequestCount($clanid);
$clan_challenges_my_clan = getOpenChallengeRequestCount($user['clan']);
$clan_challenges_oth_clan = getOpenChallengeRequestCount($clanid);
if($clan_challenges_my_clan > MAX_OPEN_REQUESTS) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
@ -82,10 +87,19 @@ function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $
return 'Der Clan "'.$oclan['clanname'].'" hat schon die maximale Anzahl von Herausforderungen offen!';
}
// select count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE
// check if both clans have already been challengeing each other since 24h?
$sql = 'SELECT count(*) as anzahl FROM clan_challenge_requests WHERE clan_requester IN ('.$user['clan'].', '.$clanid.') AND clan_challenged IN ('.$user['clan'].', '.$clanid.') AND challenged_time > TIMESTAMPADD(day, -1, now())';
$qry = mysql_query($sql);
$row = mysql_fetch_assoc($qry);
if($row['anzahl'] > 0) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
semaphoreDown($ressource_clan2); // free the previously reserved semaphore!
return 'Konnte den anderen Clan nicht herausfordern, da dieser Clan schoneinmal in den letzten 24 Stunden herausgefordert wurde!';
}
// Fordere heraus!
mysql_query('INSERT INTO clan_challenge(clan_requester, clan_challenged, type, anzahl, valid, accepted) VALUES('.$user['clan'].', '.$clanid.','.$type.' , TIMESTAMPADD(HOUR, CURRENT_TIMESTAMP, 4), '.$anzahl.', false)');
mysql_query('INSERT INTO clan_challenge_requests(clan_requester, clan_challenged, type, challenged_time, anzahl_chars, active) VALUES('.$user['clan'].', '.$clanid.','.$type.' , TIMESTAMPADD(HOUR, CURRENT_TIMESTAMP, 4), '.$anzahl.', true)');
if(mysql_affected_rows() > 0) {
if(is_numeric($oclan['leader'])) {
@ -107,10 +121,10 @@ function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $
/**
* With this function the actual user accepts the challenge request from another clan!
* @param int $clan_challenge_id
* @param int $challenged_clan the clan that has challenged us!
* @param array $user
*/
function acceptChallengeRequest($clan_challenge_id, array $user) {
function acceptChallengeRequest($challenged_clan, array $user) {
$clan = getClan($user['clan']);
if(!$clan) {
@ -121,7 +135,12 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
return 'Nur der Leader, bzw. der Co-Leader kann herausforderungen anderer Clans annehmen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM WHERE clan_challenge_id = ' .$clan_challenge_id));
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
$clan_challenge = mysql_fetch_assoc(mysql_query($sql));
if(!$clan_challenge) {
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
}
if($user['clan'] != $clan_challenge['clan_challenged']) {
return 'Du kannst die Herausforderung nicht annehmen, da du nicht im herausgeforderten Clan bist!';
@ -137,9 +156,12 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
$oclan = getClan($clan_challenge['clan_requester']);
mysql_query('UPDATE clan_challenge_requests SET accepted = TRUE WHERE clan_challenge_id = ' .$clan_challenge_id);
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())');
if(mysql_affected_rows() > 0) {
// okay and for failsaveness just deactivate old requests
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan. ' AND active = TRUE');
if(is_numeric($oclan['leader'])) {
sendMessage($user['nickname'], $oclan['leader'], 'Clan-Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Clan-Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!');
}
@ -151,8 +173,8 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
$id = -1;
// get id
while(!$finished) {
$row = mysql_fetch_row(mysql_query('select IFNULL(max(clan_challenge_id),0) + 1 from clan_challenge'));
mysql_query('INSERT INTO clan_challenge(clan_challenge_id) values('.$row[0].')');
$row = mysql_fetch_row(mysql_query('select IFNULL(max(clan_challenge_id),0) + 1 from clan_challenges'));
mysql_query('INSERT INTO clan_challenges(clan_challenge_id, type, anzahl_chars) values('.$row[0].', '.$clan_challenge['type'].', '.$clan_challenge['anzahl_chars'].')');
$finished = mysql_affected_rows() > 0;
$id = $row[0];
}
@ -172,10 +194,10 @@ function acceptChallengeRequest($clan_challenge_id, array $user) {
/**
* With this function the actual user from the challenged clan denies the challenge request!
* @param int $clan_challenge_id
* @param int $challenged_clan
* @param array $user
*/
function denyChallengeRequest($clan_challenge_id, array $user) {
function denyChallengeRequest($challenged_clan, array $user) {
$clan = getClan($user['clan']);
if(!$clan) {
@ -186,7 +208,11 @@ function denyChallengeRequest($clan_challenge_id, array $user) {
return 'Nur der Leader, bzw. der Co-Leader kann Herausforderungen anderer Clans ablehnen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM WHERE clan_challenge_id = ' .$clan_challenge_id));
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
if(!$clan_challenge) {
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
}
if($user['clan'] != $clan_challenge['clan_challenged']) {
return 'Du kannst die Herausforderung nicht ablehnen, da du nicht im herausgeforderten Clan bist!';
@ -195,7 +221,7 @@ function denyChallengeRequest($clan_challenge_id, array $user) {
}
// okay seems to be okay
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE clan_challenge_id = ' .$clan_challenge_id);
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan. ' AND active = TRUE');
return NULL;
}
@ -208,6 +234,10 @@ function getChallenge($challenge_id, $buffer = TRUE) {
if(buffer && isset($GLOBALS['clan_challenge_buffered_instances'][$challenge_id])) {
return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :)
}
$qry = mysql_query('SELECT * from clan_challenges WHERE clan_challenge_id = ' .$challenge_id);
$GLOBALS['clan_challenge_buffered_instances'][$challenge_id] = mysql_fetch_assoc($qry);
return $GLOBALS['clan_challenge_buffered_instances'][$challenge_id]; // okay, we already buffered the clan :)
}
function getOpenChallengeRequests($clanid) {
@ -216,7 +246,8 @@ function getOpenChallengeRequests($clanid) {
return $array;
}
$sql = 'SELECT * from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND clan_requester = '.$clanid.' OR clan_challenged = '.$clanid;
$sql = 'SELECT * from clan_challenge_requests WHERE challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')';
// echo $sql . '<br>';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$array[] = $row;
@ -228,7 +259,8 @@ function getOpenChallengeRequestCount($clanid) {
if(isClanLocked($clanid)) {
return 0;
}
$sql = 'SELECT count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND clan_requester = '.$clanid.' OR clan_challenged = '.$clanid;
$sql = 'SELECT count(*) from clan_challenge_requests where challenged_time > TIMESTAMPADD(day, -1, now()) and active = TRUE AND (clan_requester = '.$clanid.' OR clan_challenged = '.$clanid.')';
// echo $sql . '<br>';
$row = mysql_fetch_row(mysql_query($sql));
return $row[0];
}
@ -272,7 +304,7 @@ function getParticipatingCharIDs($clan_challenge_id, $clan_id) {
$sql = 'SELECT char_id, slot FROM clan_challenge_participants WHERE clan_challenge_id = ' . $clan_challenge_id . ' AND clan_id = ' .$clan_id;
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$array['slot'] = $row['char_id'];
$array[$row['slot']] = $row['char_id'];
}
// return the ids
return $array;
@ -296,23 +328,30 @@ function getHistoricalChallengeIDs($clanid, $limit = NULL) {
// Checks if the clan is locked, will lock it if required!
function isClanLocked($clanid) {
// we really want to know if we are locked at the moment. So readout everything at once ;), right join so we always have a row :D
$sql = 'SELECT *, locked_until < now(), (Select count(id) from user where clan = c2.id) as members FROM clan_locked right join clan c2 on c2.id = clan_locked.clanid where c2.id = ' . $clanid;
$sql = 'SELECT *, locked_until < now() as `lock`, (Select count(id) from user where clan = c2.id) as members FROM clan_locked right join clan c2 on c2.id = clan_locked.clanid where c2.id = ' . $clanid;
// echo $sql.'<br>';
$lock = mysql_fetch_assoc(mysql_query($sql));
if($lock['lock'] == 0) { // don't matter if it is 0 or NULL
// we do not have data in the clan locked table so we are not locked :D
// or
// we do have data but it seems we are not locked anymore ;)
// are we still having enough members??
if($lock['members'] >= MIN_MEMBERS) {
if($lock['members'] >= MIN_MEMBERS && $lock['lock'] === NULL) {
// key so every thing seems to be fine :)
return false; // the only case we may return false!
} else if($lock['lock'] === NULL){ // we need to insert a row
// INSERT
mysql_query('INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP)');
} else { // we have to update the actual row
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
// echo $sql.'<br>';
mysql_query($sql);
} else if($lock['members'] < MIN_MEMBERS){ // we have to update the actual row
// UPDATE
mysql_query('UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid);
$sql = 'UPDATE clan_locked set locked_until = TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP) WHERE clanid = ' .$clanid;
// echo $sql.'<br>';
mysql_query($sql);
}
}
@ -345,6 +384,10 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
$clan_challenge = getChallenge($clan_challenge_id);
if($slot < 1 && $slot > $clan_challenge['anzahl_chars']) {
return 'Der Slot ' . $slot . ' ist f&uuml;r diesen Kampf nicht verf&uuml;gbar!!';
}
$clan_ids = getParticipatingClanIDs($clan_challenge['clan_challenge_id']);
if(array_search($user['clan'], $clan_ids) === FALSE) {
@ -366,6 +409,21 @@ function joinChallenge($clan_challenge_id, array $user, $charid, $slot ) {
}
}
// okay does this user already has a char in the fight??
$qry = mysql_query('SELECT count(*) as anzahl FROM clan_challenge_participants ccp inner join chars c on ccp.char_id = c.id WHERE besitzer = ' .$user['id']);
$row = mysql_fetch_assoc($qry);
if($row['anzahl'] != 0) {
semaphoreDown($ressource);
return 'Konnte den Char nicht hinzufügen. Da du schon einen Char angemeldet hast!';
}
mysql_query('INSERT INTO clan_challenge_participants(clan_challenge_id, clan_id, char_id, slot) values('.$clan_challenge_id.', '.$user['clan'].', '.$charid.', '.$slot.')');
if(mysql_affected_rows() == 0) {
semaphoreDown($ressource);
return 'Konnte den Char nicht hinzufügen. Slot mittlerweile schon belegt?';
}
// okay, now try to update the challenge to close the challenge and to start the calculating (as long we can do it ;))
$sql = 'update clan_challenges AS cc SET calculated = TRUE WHERE '.
'(SELECT count(*) FROM clan_challenge_participants AS ccp ' .
@ -465,7 +523,7 @@ function calculateDavyBackClanFight($event_id, array $clan_ids, array $clan_char
}
$count_chars = count($clan_char_array[$clan_ids[0]]);
// okay ... now do the calculation!
for($runde = 0; $runde<$count_chars;$runde++) {
for($runde = 1; $runde<=$count_chars;$runde++) {
$char_clan_1 = $clan_char_array[$clan_ids[0]][$runde];
$char_clan_2 = $clan_char_array[$clan_ids[1]][$runde];
@ -484,10 +542,10 @@ function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char
}
$count_chars = count($clan_char_array[$clan_ids[0]]);
$counter_clan_1 = 0;
$counter_clan_2 = 0;
$char_clan_1 = $clan_char_array[$clan_ids[0]][0];
$char_clan_2 = $clan_char_array[$clan_ids[1]][0];
$counter_clan_1 = 1;
$counter_clan_2 = 1;
$char_clan_1 = $clan_char_array[$clan_ids[0]][$counter_clan_1];
$char_clan_2 = $clan_char_array[$clan_ids[1]][$counter_clan_2];
// As long as char 1 and char 2 are set
while($char_clan_1 != NULL && $char_clan_2 != NULL) {
@ -514,31 +572,32 @@ function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char
* @return the winners array
*/
function battle($event_id, array $char1, array $char2, $attack_set) {
$char1['attacke'] = implode(',', getCharAttackSet($char1['id'], $attack_set));
$char2['attacke'] = implode(',', getCharAttackSet($char2['id'], $attack_set));
$char1['attacken'] = implode(',', getCharAttackSet($char1['id'], $attack_set));
$char2['attacken'] = implode(',', getCharAttackSet($char2['id'], $attack_set));
$combinedArray = calculateFight($char1, $char2);
$exp = calculateExperience($char1, $char2, $combinedArray['winner'], 0.01); // very few exp
$combinedArray[KEY_EXP_CHAR1] = $exp[$char1['id']];
$combinedArray[KEY_EXP_CHAR2] = $exp[$char2['id']];
$combinedArray['data'][KEY_EXP_CHAR1] = $exp[$char1['id']];
$combinedArray['data'][KEY_EXP_CHAR2] = $exp[$char2['id']];
$arena = calculateArenaData(null, $char_1, $char_2, 0.01);
$combinedArray[KEY_LOGE] = $arena['loge'];
$combinedArray[KEY_SITZ] = $arena['sitz'];
$combinedArray[KEY_STEH] = $arena['steh'];
$combinedArray['data'][KEY_LOGE] = $arena['loge'];
$combinedArray['data'][KEY_SITZ] = $arena['sitz'];
$combinedArray['data'][KEY_STEH] = $arena['steh'];
if($combinedArray['winner'] == $char1['id']) {
$combinedArray[KEY_GELD_CHAR1] = $result['geld'] * 0.7;
$combinedArray[KEY_GELD_CHAR2] = $result['geld'] * 0.3;
$combinedArray['data'][KEY_GELD_CHAR1] = $result['geld'] * 0.7;
$combinedArray['data'][KEY_GELD_CHAR2] = $result['geld'] * 0.3;
} else {
$combinedArray[KEY_GELD_CHAR2] = $result['geld'] * 0.7;
$combinedArray[KEY_GELD_CHAR1] = $result['geld'] * 0.3;
$combinedArray['data'][KEY_GELD_CHAR2] = $result['geld'] * 0.7;
$combinedArray['data'][KEY_GELD_CHAR1] = $result['geld'] * 0.3;
}
// first persist the fight and then check who was the winner and adjust the char array for him ;)
persistFight($event_id, $combinedArray);
return;
// now get the winners array
$rounds = $combinedArray['rounds'];

@ -10,6 +10,7 @@ include_once ($_SERVER['DOCUMENT_ROOT'].'ag/include/config/db.inc.php');
$GLOBALS['definesInitialized'] = FALSE;
$GLOBALS['definesEditable'] = array();
function initializeDefines() {
$sql = 'SELECT * from defines';
@ -17,22 +18,28 @@ function initializeDefines() {
while($row = mysql_fetch_assoc($qry)) {
if(!defined($row['key'])) {
define($row['key'], $row['value']);
$GLOBALS['definesEditable'][$row['key']] = $row['editable'];
}
}
$GLOBALS['definesInitialized'] = TRUE;
}
function defineIfNotDefined($key, $value) {
function defineIfNotDefined($key, $value, $editable = TRUE) {
if(!$GLOBALS['definesInitialized']) {
initializeDefines();
}
if(!defined($key)) {
// we seem that we need to insert this key - value pair!
$sql = 'INSERT INTO defines(`key`, `value`) values(\''.$key.'\', \''.$value.'\')';
$sql = 'INSERT INTO defines(`key`, `value`, `editable`) values(\''.$key.'\', \''.$value.'\', \''.$editable.'\')';
mysql_query($sql);
define($key, $value);
} else if($GLOBALS['definesEditable'][$key] != $editable){
// if the editableness of this value has been changed, adjust the database ;)
$sql = 'UPDATE defines SET editable = ' . ($editable?'1':'0') . ' WHERE `key` = \'' .$key.'\'';
// echo $sql.'<br>';
mysql_query($sql);
}
}

@ -88,7 +88,6 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
// persist a fight of two chars (calculated by the wrapper) ^^"
//echo 'The fight was about ' . count($combinedArray) . ' rounds <br>';
$roundsArray = $combinedArray['rounds'];
$winnerId = $combinedArray['winner'];
$hostId = $combinedArray['host'];
@ -100,7 +99,9 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
while(!$finished) {
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
$row = mysql_fetch_row(mysql_query($sql));
mysql_query('INSERT INTO event_fights(event_id, event_fight_id, host, winner) values('.$event_id.', \''.$row[0].'\, '. $hostId . ', ' . $winnerId .')');
$sql = 'INSERT INTO event_fights(event_id, event_fight_id, host, winner) values('.$event_id.', \''.$row[0].'\', '. $hostId . ', ' . $winnerId .')';
if(mysql_query($sql) === FALSE)
break;
$finished = mysql_affected_rows() > 0;
$event_fight_id = $row[0];
}
@ -134,7 +135,8 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
// Okay now do we have any additional data left?
foreach ($data as $key => $value) {
$sql = 'INSERT INTO event_fight_metadata(event_id, event_fight_id, key, value) values('.$event_id.','.$event_fight_id.',\''.$key.'\',\''.$value.'\')';
$sql = 'INSERT INTO event_fight_metadata(event_id, event_fight_id, `key`, `value`) values('.$event_id.','.$event_fight_id.',\''.$key.'\',\''.$value.'\')';
// echo $sql . ' <br>';
mysql_query($sql);
}
}

@ -227,7 +227,7 @@ function calculateFight(array $char1, array $char2) {
$metaData['rounds'] = $rundenArray;
$metaData['data'] = array();
return $rundenArray;
return $metaData;
}

@ -6,25 +6,131 @@
*
*/
//include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/kampf_wrapper.inc.php');
//include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/event.inc.php');
//include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/char.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/user.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/parse.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/clan.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/clan_fights.inc.php');
//$event_id = createEvent(EVENT_TEST);
$acceptTestCase = true;
//$charid = addParticipant($event_id, getChar(4113));
//$charid = addParticipant($event_id, getChar(4162));
mysql_query('DELETE FROM clan_challenge_requests');
mysql_query('DELETE FROM clan_challenges');
//$combinedArray = calculateFight(getChar(4113), getChar(4162));
$clan1 = getClan(786);
$clan2 = getClan(783);
//persistFight($event_id, $combinedArray);
$leaderClan1 = getUser($clan1['leader']);
$leaderClan2 = getUser($clan2['leader']);
include_once ($_SERVER['DOCUMENT_ROOT'].'ag/include/defines.inc.php');
$result = challengeClan($leaderClan1, $clan2['id'], 1);
if($result !== NULL) {
echo $result.'<br>';
}
defineIfNotDefined('TEST', 1);
if(getOpenChallengeRequestCount($clan1['id']) != 1) {
echo 'Fehler: Es sollte mindestens ein Fight offen sein!!<br>';
}
if(getOpenChallengeRequestCount($clan2['id']) != 1) {
echo 'Fehler: Es sollte mindestens ein Fight offen sein!!<br>';
}
if(count(getOpenChallengeRequests($clan1['id'])) != 1) {
echo 'Fehler: Es sollte mindestens ein Fight offen sein!!<br>';
}
if(count(getOpenChallengeRequests($clan2['id'])) != 1) {
echo 'Fehler: Es sollte mindestens ein Fight offen sein!!<br>';
}
$challengeArray = getOpenChallengeRequests($clan2['id']);
if($acceptTestCase) {
$result = acceptChallengeRequest($challengeArray[0]['clan_requester'], $leaderClan2);
if($result !== NULL) {
echo $result.'<br>';
}
if(getOpenChallengeRequestCount($clan1['id']) > 0) {
echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!<br>';
}
if(getOpenChallengeRequestCount($clan2['id']) > 0) {
echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!<br>';
}
if(count(getOpenChallengeRequests($clan1['id'])) > 0) {
echo 'Fehler in getOpenChallengeRequests ('.$clan1['id'].'): Es sollte kein Fight-Request offen sein!!<br>';
}
if(count(getOpenChallengeRequests($clan2['id'])) > 0) {
echo 'Fehler in getOpenChallengeRequests ('.$clan2['id'].'): Es sollte kein Fight-Request offen sein!!<br>';
}
if(count(getOpenChallengeIDs($clan1['id'])) != 1) {
echo 'Fehler: Es sollte mindestens ein Fight offen sein!!<br>';
}
if(count(getOpenChallengeIDs($clan2['id'])) != 1) {
echo 'Fehler: Es sollte mindestens ein Fight offen sein!!<br>';
}
$challengeIDsArray = getOpenChallengeIDs($clan1['id']);
$clan_challenge_id = $challengeIDsArray[0];
if(count(getParticipatingClanIDs($clan_challenge_id)) != 2) {
echo 'Fehler in getParticipatingClanIDs: Es sollten 2 Clans teilnehmen!<br>';
}
// Okay now let the chars participate
$chars1 = getCharsOfUser($leaderClan1['id']);
$chars2 = getCharsOfUser($leaderClan2['id']);
$result = joinChallenge($clan_challenge_id, $leaderClan1, $chars1[0]['id'], 1);
if($result !== NULL) {
echo $result .'<br>';
}
$result = joinChallenge($clan_challenge_id, $leaderClan1, $chars1[1]['id'], 2);
if($result === NULL) {
echo 'Error: Es war möglich einen zweiten Char desselben Users hinzuzufügen!!';
}
$result = joinChallenge($clan_challenge_id, $leaderClan2, $chars2[0]['id'], 1);
if($result !== NULL) {
echo $result .'<br>';
}
} else {
$result = denyChallengeRequest($challengeArray[0]['clan_requester'], $leaderClan2);
if($result !== NULL) {
echo $result .'<br>';
}
if(getOpenChallengeRequestCount($clan1['id']) > 0) {
echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!<br>';
}
if(getOpenChallengeRequestCount($clan2['id']) > 0) {
echo 'Fehler in getOpenChallengeRequestCount: Es sollte kein Fight-Request offen sein!!<br>';
}
if(count(getOpenChallengeRequests($clan1['id'])) > 0) {
echo 'Fehler in getOpenChallengeRequests ('.$clan1['id'].'): Es sollte kein Fight-Request offen sein!!<br>';
}
if(count(getOpenChallengeRequests($clan2['id'])) > 0) {
echo 'Fehler in getOpenChallengeRequests ('.$clan2['id'].'): Es sollte kein Fight-Request offen sein!!<br>';
}
}
echo TEST;
?>

@ -2314,6 +2314,7 @@ CREATE TABLE `clan_challenge_participants` (
PRIMARY KEY (`clan_challenge_id`,`clan_id`,`slot`),
KEY `clan_challenge_participants_clan_id` (`clan_id`),
KEY `clan_challenge_participants_char_id` (`char_id`),
UNIQUE (`clan_challenge_id`, `clan_id`, `slot`),
CONSTRAINT `clan_challenge_participants_char_id` FOREIGN KEY (`char_id`) REFERENCES `chars` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `clan_challenge_participants_clan_id` FOREIGN KEY (`clan_challenge_id`, `clan_id`) REFERENCES `clan_challenge_clans` (`clan_challenge_id`, `clan_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -2495,6 +2496,7 @@ DROP TABLE IF EXISTS `defines`;
CREATE TABLE `defines` (
`key` VARCHAR(30) NOT NULL,
`value` VARCHAR(20) NOT NULL,
`editable` BOOLEAN NOT NULL,
PRIMARY KEY (`key`)
)
ENGINE = InnoDB

Loading…
Cancel
Save