1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/* Tenes Empanadas Graciela
*
* Copyright (C) 2000 Ricardo Quesada
*
* Author: Ricardo Calixto Quesada <riq@corest.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; only version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/* functions that sends tokens to the server */
#include <string.h>
#include <stdio.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include "fcintl.h"
#include "net.h"
#include "client.h"
#include "protocol.h"
namespace teg::client
{
TEG_STATUS out_mensaje(char *msg)
{
if(ESTADO_MENOR(PLAYER_STATUS_CONNECTED)) {
return TEG_STATUS_NOTCONNECTED;
}
strip_invalid_msg(msg);
net_printf(g_game.fd, TOKEN_MESSAGE"=\"%s\"\n", msg);
return TEG_STATUS_SUCCESS;
}
/* tells the server who am i */
TEG_STATUS out_id()
{
if(ESTADO_MAYOR_IGUAL(PLAYER_STATUS_CONNECTED)) {
return TEG_STATUS_ERROR;
}
strip_invalid(g_game.myname);
net_printf(g_game.fd, TOKEN_PLAYERID"=%s,%d,%d\n", g_game.myname, !g_game.observer, g_game.human);
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_color(int color)
{
if(ESTADO_MAYOR_IGUAL(PLAYER_STATUS_HABILITADO)) {
return TEG_STATUS_ERROR;
}
net_printf(g_game.fd, TOKEN_COLOR"=%d\n", color);
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_exit()
{
if(ESTADO_MENOR(PLAYER_STATUS_CONNECTED)) {
return TEG_STATUS_NOTCONNECTED;
}
net_printf(g_game.fd, TOKEN_EXIT"\n");
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_countries()
{
if(ESTADO_MENOR(PLAYER_STATUS_CONNECTED)) {
textmsg(M_ERR, _("Error, you must be connected"));
return TEG_STATUS_NOTCONNECTED;
}
net_printf(g_game.fd, TOKEN_COUNTRIES"=-1\n");
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_enum_cards()
{
if(ESTADO_MENOR(PLAYER_STATUS_CONNECTED)) {
textmsg(M_ERR, _("Error, you must be connected"));
return TEG_STATUS_NOTCONNECTED;
}
net_printf(g_game.fd, TOKEN_ENUM_CARDS"\n");
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_new_round()
{
if(ESTADO_MENOR(PLAYER_STATUS_CONNECTED)) {
textmsg(M_ERR, _("Error, you must be connected"));
return TEG_STATUS_NOTCONNECTED;
}
net_printf(g_game.fd, TOKEN_NEW_ROUND"\n");
return TEG_STATUS_SUCCESS;
}
/* request the server the type of game */
TEG_STATUS out_status()
{
if(ESTADO_MENOR(PLAYER_STATUS_CONNECTED)) {
return TEG_STATUS_NOTCONNECTED;
}
net_printf(g_game.fd, TOKEN_STATUS"\n");
return TEG_STATUS_SUCCESS;
}
/* start the game */
TEG_STATUS out_start()
{
if(ESTADO_ES(PLAYER_STATUS_HABILITADO)) {
net_printf(g_game.fd, TOKEN_START"\n");
return TEG_STATUS_SUCCESS;
}
return TEG_STATUS_NOTCONNECTED;
}
TEG_STATUS out_tarjeta()
{
if(ESTADO_MENOR(PLAYER_STATUS_ATAQUE) || ESTADO_MAYOR_IGUAL(PLAYER_STATUS_TARJETA)) {
textmsg(M_ERR, _("Error, it's not the moment to get a card"));
return TEG_STATUS_ERROR;
}
net_printf(g_game.fd, TOKEN_TARJETA"\n");
return TEG_STATUS_SUCCESS;
}
/* send the server the armies I'm moving after conquering a country */
TEG_STATUS out_tropas(int src, int dst, int cant)
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e==PLAYER_STATUS_TROPAS || e==PLAYER_STATUS_ATAQUE) {
net_printf(g_game.fd, TOKEN_TROPAS"=%d,%d,%d\n", src, dst, cant);
} else {
return TEG_STATUS_ERROR;
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_endturn()
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e > PLAYER_STATUS_TURNOSTART && e < PLAYER_STATUS_TURNOEND) {
attack_reset();
reagrupe_reset();
ESTADO_SET(PLAYER_STATUS_IDLE);
net_printf(g_game.fd, TOKEN_TURNO"\n");
} else {
textmsg(M_ERR, _("Error, it's not your turn."));
return TEG_STATUS_ERROR;
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_surrender()
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e >= PLAYER_STATUS_START) {
net_printf(g_game.fd, TOKEN_SURRENDER"\n");
return TEG_STATUS_SUCCESS;
}
return TEG_STATUS_ERROR;
}
TEG_STATUS out_missions()
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e >= PLAYER_STATUS_START) {
net_printf(g_game.fd, TOKEN_MISSION"\n");
} else {
textmsg(M_ERR, _("Error, the game is not started"));
return TEG_STATUS_ERROR;
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_get_typeofgame()
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e >= PLAYER_STATUS_START) {
net_printf(g_game.fd, TOKEN_MODALIDAD"\n");
} else {
textmsg(M_ERR, _("Error, the game is not started"));
return TEG_STATUS_ERROR;
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_set_typeofgame(int conqworld, int fog_of_war, int with_common, int armies1, int armies2)
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e >= PLAYER_STATUS_START) {
textmsg(M_ERR, _("Error, the game is started so you cant change the type of game"));
return TEG_STATUS_ERROR;
} else {
net_printf(g_game.fd, "%s=%s=%d;%s=%s=%d;%s=%s=%d;%s=%s=%d,%d\n",
TOKEN_SET, OPTION_CONQWORLD, conqworld,
TOKEN_SET, OPTION_FOG_OF_WAR, fog_of_war,
TOKEN_SET, OPTION_CMISSION, with_common,
TOKEN_SET, OPTION_ARMIES, armies1, armies2
);
}
return TEG_STATUS_SUCCESS;
}
TEG_STATUS out_loque(void)
{
PLAYER_STATUS e;
e = ESTADO_GET();
if(e >= PLAYER_STATUS_CONNECTED) {
net_printf(g_game.fd, TOKEN_LOQUE"\n");
return TEG_STATUS_SUCCESS;
}
return TEG_STATUS_ERROR;
}
/* ask for scores */
TEG_STATUS out_scores()
{
PLAYER_STATUS e = ESTADO_GET();
if(e >= PLAYER_STATUS_CONNECTED && g_game.fd > 0) {
net_printf(g_game.fd, TOKEN_SCORES"\n");
return TEG_STATUS_SUCCESS;
}
return TEG_STATUS_ERROR;
}
/* request a robot */
TEG_STATUS out_robot()
{
PLAYER_STATUS e = ESTADO_GET();
if(e >= PLAYER_STATUS_CONNECTED && e < PLAYER_STATUS_START && g_game.fd > 0) {
net_printf(g_game.fd, TOKEN_ROBOT"\n");
return TEG_STATUS_SUCCESS;
}
return TEG_STATUS_ERROR;
}
}
|