add WOL quickmatch player ability to prefer colour/country

This commit is contained in:
Pelish 2010-02-06 23:10:12 +00:00
parent 7af1cd6537
commit 97bdc50374
4 changed files with 132 additions and 12 deletions

View file

@ -97,6 +97,8 @@ static t_anongame_wol_player * anongame_wol_player_create(t_connection * conn)
/* Used only in Red Alert 2 and Yuri's Revenge */
player->address = 0;
player->port = 0;
player->country = -2; /* Default values are form packet dumps - not prefered country */
player->colour = -2; /* Default values are form packet dumps - not prefered colour */
conn_wol_set_anongame_player(conn, player);
@ -333,6 +335,25 @@ static int _send_msg(t_connection * conn, char const * command, char const * tex
return 0;
}
static int _get_pair(int * i, int * j, int max, bool different)
{
max++; /* We want to use just real maximum number - no metter what function do */
if (*i == -2)
*i = (max * rand() / (RAND_MAX + 1));
if (*j == -2)
*j = (max * rand() / (RAND_MAX + 1));
if ((different) && (*i == *j)) {
do {
*j = (max * rand() / (RAND_MAX + 1));
} while (*i == *j);
}
return 0;
}
static int anongame_wol_trystart(t_anongame_wol_player const * player1)
{
t_elem * curr;
@ -379,22 +400,31 @@ static int anongame_wol_trystart(t_anongame_wol_player const * player1)
if ((player1 != player2) && ((conn_get_channel(conn_pl1)) == (conn_get_channel(conn_pl2)))) {
switch (ctag) {
case CLIENTTAG_REDALERT2_UINT:
case CLIENTTAG_REDALERT2_UINT: {
random = rand();
if (std::strcmp(channelname , RAL2_CHANNEL_FFA) == 0) {
mapname = anongame_get_map_from_prefs(ANONGAME_TYPE_1V1, ctag);
int pl1_colour = anongame_wol_player_get_colour(player1);
int pl1_country = anongame_wol_player_get_country(player1);
int pl2_colour = anongame_wol_player_get_colour(player2);
int pl2_country = anongame_wol_player_get_country(player2);
DEBUG0("Generating SOLO game for Red Alert 2");
/* We have madatory of game */
_get_pair(&pl1_colour,&pl2_colour, 7, true);
_get_pair(&pl1_country,&pl2_country, 8, false);
mapname = anongame_get_map_from_prefs(ANONGAME_TYPE_1V1, ctag);
/* We have madatory of game */
snprintf(_temp, sizeof(_temp), ":Start %u,0,0,10000,0,1,0,1,1,0,1,x,2,1,165368,%s,1:", random, mapname);
std::strcat(temp,_temp);
/* GameHost informations */
snprintf(_temp, sizeof(_temp),"%s,8,4,%x,1,%x,",conn_get_chatname(conn_pl1),anongame_wol_player_get_address(player1),anongame_wol_player_get_port(player1));
snprintf(_temp, sizeof(_temp),"%s,%d,%d,%x,1,%x,", conn_get_chatname(conn_pl1), pl1_country, pl1_colour, anongame_wol_player_get_address(player1),anongame_wol_player_get_port(player1));
std::strcat(temp,_temp);
/* GameJoinie informations */
snprintf(_temp, sizeof(_temp),"%s,5,2,%x,1,%x",conn_get_chatname(conn_pl2),anongame_wol_player_get_address(player2),anongame_wol_player_get_port(player2));
snprintf(_temp, sizeof(_temp),"%s,%d,%d,%x,1,%x", conn_get_chatname(conn_pl2), pl2_country, pl2_colour, anongame_wol_player_get_address(player2),anongame_wol_player_get_port(player2));
std::strcat(temp,_temp);
_send_msg(conn_pl1,"PRIVMSG",temp);
@ -402,26 +432,35 @@ static int anongame_wol_trystart(t_anongame_wol_player const * player1)
}
else
ERROR1("undefined channel type for %s channel", channelname);
}
return 0;
case CLIENTTAG_YURISREV_UINT:
case CLIENTTAG_YURISREV_UINT: {
random = rand();
if (std::strcmp(channelname , YURI_CHANNEL_FFA) == 0) {
mapname = anongame_get_map_from_prefs(ANONGAME_TYPE_1V1, ctag);
int pl1_colour = anongame_wol_player_get_colour(player1);
int pl1_country = anongame_wol_player_get_country(player1);
int pl2_colour = anongame_wol_player_get_colour(player2);
int pl2_country = anongame_wol_player_get_country(player2);
DEBUG0("Generating SOLO game for Yuri's Revenge");
_get_pair(&pl1_colour,&pl2_colour, 7, true);
_get_pair(&pl1_country,&pl2_country, 9, false);
mapname = anongame_get_map_from_prefs(ANONGAME_TYPE_1V1, ctag);
/* We have madatory of game */
snprintf(_temp, sizeof(_temp), ":Start %u,0,0,10000,0,0,1,1,1,0,3,0,x,2,1,163770,%s,1:", random, mapname);
std::strcat(temp,_temp);
/* GameHost informations */
snprintf(_temp, sizeof(_temp),"%s,1,4,-2,-2,",conn_get_chatname(conn_pl1));
snprintf(_temp, sizeof(_temp),"%s,%d,%d,-2,-2,", conn_get_chatname(conn_pl1), pl1_country, pl1_colour);
std::strcat(temp,_temp);
snprintf(_temp, sizeof(_temp),"%x,1,%x,",anongame_wol_player_get_address(player1),anongame_wol_player_get_port(player1));
std::strcat(temp,_temp);
/* GameJoinie informations */
snprintf(_temp, sizeof(_temp),"%s,6,5,-2,-2,",conn_get_chatname(anongame_wol_player_get_conn(player2)));
snprintf(_temp, sizeof(_temp),"%s,%d,%d,-2,-2,",conn_get_chatname(conn_pl2), pl2_country, pl2_colour);
std::strcat(temp,_temp);
snprintf(_temp, sizeof(_temp),"%x,1,%x",anongame_wol_player_get_address(player2),anongame_wol_player_get_port(player2));
std::strcat(temp,_temp);
@ -457,6 +496,7 @@ static int anongame_wol_trystart(t_anongame_wol_player const * player1)
}
else
ERROR1("undefined channel type for %s channel", channelname);
}
return 0;
default:
DEBUG0("unsupported client for WOL Matchgame");

View file

@ -514,7 +514,7 @@ static int append_game_info(t_game* game, void* vdata)
*/
/**
* The layout of the game list entry is something like this:
* #game_channel_name users unknown gameType gameIsTournment gameExtension longIP LOCK::topic
* #game_channel_name currentusers maxplayers gameType gameIsTournment gameExtension longIP LOCK::topic
*/
std::strcat(temp,gamename);
@ -543,7 +543,7 @@ static int append_game_info(t_game* game, void* vdata)
else
std::strcat(temp,"384"); /* game is loocked 384 == pass */
std::strcat(temp,"::");
std::strcat(temp,"::");
if (topic) {
snprintf(temp_a, sizeof(temp_a), "%s", topic); /* topic */

View file

@ -187,6 +187,15 @@ static int _client_col5(t_wol_gameres_result * game_result, wol_gameres_type typ
static int _client_col6(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_col7(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd0(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd1(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd2(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd3(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd4(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd5(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd6(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_crd7(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_inb0(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_inb1(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
static int _client_inb2(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data);
@ -456,6 +465,15 @@ static const t_wol_gamerestag_table_row wol_gamreres_htable[] = {
{CLIENT_COL6_UINT, _client_col6},
{CLIENT_COL7_UINT, _client_col7},
{CLIENT_CRD0_UINT, _client_crd0},
{CLIENT_CRD1_UINT, _client_crd1},
{CLIENT_CRD2_UINT, _client_crd2},
{CLIENT_CRD3_UINT, _client_crd3},
{CLIENT_CRD4_UINT, _client_crd4},
{CLIENT_CRD5_UINT, _client_crd5},
{CLIENT_CRD6_UINT, _client_crd6},
{CLIENT_CRD7_UINT, _client_crd7},
{CLIENT_INB0_UINT, _client_inb0},
{CLIENT_INB1_UINT, _client_inb1},
{CLIENT_INB2_UINT, _client_inb2},
@ -2528,6 +2546,59 @@ static int _client_col7(t_wol_gameres_result * game_result, wol_gameres_type typ
return _cl_col_general(7, type, size, data);
}
static int _cl_crd_general(int num, wol_gameres_type type, int size, void const * data)
{
switch (type) {
case wol_gameres_type_time:
DEBUG2("Player %u had %u credits on end of game", num, (unsigned int) bn_int_nget(*((bn_int *)data)));
break;
default:
WARN2("got unknown gameres type %u for CRD%u", type, num);
break;
}
return 0;
}
static int _client_crd0(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(0, type, size, data);
}
static int _client_crd1(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(1, type, size, data);
}
static int _client_crd2(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(2, type, size, data);
}
static int _client_crd3(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(3, type, size, data);
}
static int _client_crd4(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(4, type, size, data);
}
static int _client_crd5(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(5, type, size, data);
}
static int _client_crd6(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(6, type, size, data);
}
static int _client_crd7(t_wol_gameres_result * game_result, wol_gameres_type type, int size, void const * data)
{
return _cl_crd_general(7, type, size, data);
}
static int _cl_inb_general(int num, wol_gameres_type type, int size, void const * data)
{
switch (type) {

View file

@ -213,6 +213,15 @@ const t_tag CLIENT_COL5_UINT = 0x434f4c35;
const t_tag CLIENT_COL6_UINT = 0x434f4c36;
const t_tag CLIENT_COL7_UINT = 0x434f4c37;
const t_tag CLIENT_CRD0_UINT = 0x43524430;
const t_tag CLIENT_CRD1_UINT = 0x43524431;
const t_tag CLIENT_CRD2_UINT = 0x43524432;
const t_tag CLIENT_CRD3_UINT = 0x43524433;
const t_tag CLIENT_CRD4_UINT = 0x43524434;
const t_tag CLIENT_CRD5_UINT = 0x43524435;
const t_tag CLIENT_CRD6_UINT = 0x43524436;
const t_tag CLIENT_CRD7_UINT = 0x43524437;
const t_tag CLIENT_INB0_UINT = 0x494e4230;
const t_tag CLIENT_INB1_UINT = 0x494e4231;
const t_tag CLIENT_INB2_UINT = 0x494e4232;