summaryrefslogtreecommitdiff
path: root/src/zal_proto.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-04-04 18:46:15 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-04-04 18:46:15 +0000
commit6dbcded21e7e9614b967b922987be6bcf3f3fe58 (patch)
treecfa806296d8880c4136681c5cb96d06a2e856eb0 /src/zal_proto.c
parent617ba439aab5f1798eb02618dfcfbed80a5baf28 (diff)
- moznost nastavit si klavesy na ovladanie v ~/.tuxanci-ng/keycontrol.conf
- moznost prekladat texty do roznych jazykov, defult jazyk je EN, nastavenie je v ~/.tuxanci-ng/lang.conf - moznost nastavit server pomocou konfiguraku ./server.conf - uptime v sekudach a samorestartovaci casocvac tam este _NIE_ _JE_ git-svn-id: http://opensvn.csie.org/tuxanci_ng@39 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/zal_proto.c')
-rw-r--r--src/zal_proto.c692
1 files changed, 692 insertions, 0 deletions
diff --git a/src/zal_proto.c b/src/zal_proto.c
new file mode 100644
index 0000000..a091e19
--- /dev/null
+++ b/src/zal_proto.c
@@ -0,0 +1,692 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+#include "item.h"
+#include "shot.h"
+#include "arenaFile.h"
+#include "myTimer.h"
+#include "server.h"
+#include "proto.h"
+#include "net_multiplayer.h"
+
+#ifndef PUBLIC_SERVER
+#include "network.h"
+#include "screen_world.h"
+#include "screen_setting.h"
+#include "screen_choiceArena.h"
+#include "client.h"
+#include "term.h"
+#endif
+
+#ifdef PUBLIC_SERVER
+#include "publicServer.h"
+#endif
+
+static void proto_send(int type, client_t *client, char *msg)
+{
+ assert( msg != NULL );
+
+ switch( type )
+ {
+ case PROTO_SEND_ONE :
+ assert( client != NULL );
+ sendClient(client, msg);
+#ifdef DEBUG_SERVER_SEND
+ printf("send one client msg->%s\n", msg);
+#endif
+ break;
+ case PROTO_SEND_ALL :
+ assert( client == NULL );
+ sendAllClient(msg);
+#ifdef DEBUG_SERVER_SEND
+ printf("send all clients msg->%s\n", msg);
+#endif
+ break;
+ case PROTO_SEND_BUT :
+ assert( client != NULL );
+ sendAllClientBut(msg, client);
+#ifdef DEBUG_SERVER_SEND
+ printf("send but client msg->%s\n", msg);
+#endif
+ break;
+ default :
+ assert( ! "Premenna type ma zlu hodnotu !" );
+ break;
+ }
+}
+
+void proto_send_error_server(int type, client_t *client, int errorcode)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "error %d\n", errorcode);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_error_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int errorcode;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d",
+ cmd, &errorcode);
+
+ printf("proto error code %d\n", errorcode);
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_hello_client(char *name)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "hello %s %s\n", TUXANCI_NG_VERSION, name);
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_hello_server(client_t *client, char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ char version[STR_NAME_SIZE];
+ char name[STR_NAME_SIZE];
+
+ assert( client != NULL );
+
+ strcpy(version, "");
+ strcpy(name, "");
+
+ sscanf(msg, "%s %s %s", cmd, version, name);
+
+ if( strncmp(version, TUXANCI_NG_VERSION, strlen(TUXANCI_NG_VERSION)) != 0 )
+ {
+ proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION);
+ client->status = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ client->tux = newTux();
+ client->tux->control = TUX_CONTROL_NET;
+ addList(getCurrentArena()->listTux, client->tux);
+
+ if( strlen(name) > STR_NAME_SIZE-1 )
+ {
+ name[STR_NAME_SIZE-1] = '\0';
+ }
+
+ strcpy(client->tux->name, name);
+ sendInfoCreateClient(client);
+}
+
+void proto_send_status_server(int type, client_t *client)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "version: %s\n"
+ "clients: %d\n"
+ "maxclients: %d\n"
+ "uptime: %d\n",
+ TUXANCI_NG_VERSION, getCurrentArena()->listTux->count,
+ getServerMaxClients(), getMyTime() );
+
+ proto_send(type, client, msg);
+}
+
+void proto_recv_status_server(client_t *client, char *msg)
+{
+ proto_send_status_server(PROTO_SEND_ONE, client);
+}
+
+void proto_send_init_server(int type, client_t *client, client_t *client2)
+{
+ char msg[STR_PROTO_SIZE];
+ int n = WORLD_COUNT_ROUND_UNLIMITED;
+
+ assert( client2 != NULL );
+
+#ifndef PUBLIC_SERVER
+ getSettingCountRound(&n);
+#endif
+
+ sprintf(msg, "init %d %d %d %d %s\n",
+ client2->tux->id, client2->tux->x, client2->tux->y,
+ n, getArenaNetName( getChoiceArenaId() ));
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_init_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ char arena_name[STR_PROTO_SIZE];
+ tux_t *tux;
+ int id;
+ int x, y, n;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %s",
+ cmd, &id, &x, &y, &n, arena_name);
+
+ setWorldArena( getArenaIdFormNetName(arena_name) );
+ setMaxCountRound(n);
+
+ tux = newTux();
+ tux->id = id;
+ tux->x = x;
+ tux->y = y;
+ tux->control = TUX_CONTROL_KEYBOARD_RIGHT;
+
+ getSettingNameRight(tux->name);
+
+ addList(getCurrentArena()->listTux, tux);
+}
+
+#endif
+
+void proto_send_event_server(int type, client_t *client, tux_t *tux, int action)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( tux != NULL );
+
+ sprintf(msg, "event %d %d\n", tux->id, action);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_event_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id, action;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d", cmd, &id, &action);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ actionTux(tux, action);
+ }
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_event_client(int action)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "event %d\n", action);
+
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_event_server(client_t *client, char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int action;
+
+ assert( client != NULL );
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d", cmd, &action);
+
+ proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action);
+
+ actionTux(client->tux, action);
+
+}
+
+void proto_send_newtux_server(int type, client_t *client, tux_t *tux)
+{
+ char msg[STR_PROTO_SIZE];
+ int x, y;
+
+ assert( tux != NULL );
+
+ if( tux->bonus == BONUS_HIDDEN )
+ {
+ x = TUX_LOCATE_UNKNOWN;
+ y = TUX_LOCATE_UNKNOWN;
+ }
+ else
+ {
+ x = tux->x;
+ y = tux->y;
+ }
+
+ sprintf(msg, "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n",
+ tux->id ,x, y, tux->status, tux->position ,tux->frame, tux->score, tux->name,
+ tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE],
+ tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER],
+ tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL],
+ tux->bonus_time, tux->pickup_time);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_newtux_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ char name[STR_NAME_SIZE];
+ int id, x, y, status, position, frame, score;
+ int myGun, myBonus;
+ int gun1, gun2, gun3, gun4, gun5, gun6, gun7;
+ int time1, time2;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ cmd, &id, &x, &y, &status, &position, &frame, &score, name,
+ &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux == NULL )
+ {
+ char term_msg[STR_SIZE];
+ sprintf(term_msg, "connect new client( id = %d)\n", id);
+ appendTextInTerm(term_msg);
+
+ tux = newTux();
+ tux->control = TUX_CONTROL_NET;
+ addList(getCurrentArena()->listTux, tux);
+ }
+
+ tux->id = id;
+
+ tux->x = x;
+ tux->y = y;
+ tux->status = status;
+ tux->position = position;
+ tux->frame = frame;
+ tux->score = score;
+ strcpy(tux->name, name);
+ tux->gun = myGun;
+ tux->bonus = myBonus;
+ tux->shot[GUN_SIMPLE] = gun1;
+ tux->shot[GUN_DUAL_SIMPLE] = gun2;
+ tux->shot[GUN_SCATTER] = gun3;
+ tux->shot[GUN_TOMMY] = gun4;
+ tux->shot[GUN_LASSER] = gun5;
+ tux->shot[GUN_MINE] = gun6;
+ tux->shot[GUN_BOMBBALL] = gun7;
+ tux->bonus_time = time1;
+ tux->pickup_time = time2;
+}
+
+#endif
+
+void proto_send_kill_server(int type, client_t *client, tux_t *tux)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( tux != NULL );
+
+ sprintf(msg, "kill %d\n", tux->id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_kill_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d", cmd, &id);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ eventTuxIsDead(tux);
+ }
+}
+
+#endif
+
+void proto_send_score_server(int type, client_t *client, tux_t *tux)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( tux != NULL );
+
+ sprintf(msg, "score %d %d\n", tux->id, tux->score);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_score_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id, score;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d", cmd, &id, &score);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ char term_msg[STR_SIZE];
+ sprintf(term_msg, "tux with id %d set score to %d\n", tux->id, score);
+ appendTextInTerm(term_msg);
+
+ tux->score = score;
+ }
+
+ countRoundInc();
+}
+
+#endif
+
+void proto_send_deltux_server(int type, client_t *client, client_t *client2)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( client2 != NULL );
+
+ sprintf(msg, "deltux %d\n", client2->tux->id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_deltux_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d", cmd, &id);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ char term_msg[STR_SIZE];
+ int index;
+
+ sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
+ appendTextInTerm(term_msg);
+
+ index = searchListItem(getCurrentArena()->listTux, tux);
+ delListItem(getCurrentArena()->listTux, index, destroyTux);
+ }
+}
+
+#endif
+
+void proto_send_additem_server(int type, client_t *client, item_t *p)
+{
+ char msg[STR_PROTO_SIZE];
+ int id = -1;
+
+ assert( p != NULL );
+
+ if( p->author != NULL )
+ {
+ id = p->author->id;
+ }
+
+ sprintf(msg, "additem %d %d %d %d %d %d %d\n",
+ p->id, p->type, p->x, p->y, p->count, p->frame, id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_additem_client(char *msg)
+{
+ char term_msg[STR_SIZE];
+ char cmd[STR_PROTO_SIZE];
+ int id, type, x, y, count, frame, author_id;
+ item_t *item;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %d %d %d", cmd, &id, &type, &x, &y, &count, &frame, &author_id);
+
+ if( getItemID(getCurrentArena()->listItem, id) != NULL )
+ {
+ return;
+ }
+
+ item = newItem(x, y, type, getTuxID(getCurrentArena()->listTux, author_id));
+/*
+ if( isConflictWithListItem(getCurrentArena()->listItem, item->x, item->y, item->w, item->h) )
+ {
+ destroyItem(item);
+ return;
+ }
+*/
+ item->id = id;
+ item->count = count;
+ item->frame = frame;
+
+ addList(getCurrentArena()->listItem, item);
+
+ sprintf(term_msg, "in arena is new item\n");
+ appendTextInTerm(term_msg);
+
+}
+
+#endif
+
+void proto_send_item_server(int type, client_t *client, tux_t *tux, item_t *item)
+{
+ char msg[STR_PROTO_SIZE];
+ int tux_id = -1;
+
+ assert( item != NULL );
+
+ if( tux != NULL )
+ {
+ tux_id = tux->id;
+ }
+
+ sprintf(msg, "item %d %d\n",
+ tux_id, item->id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_item_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int tux_id, item_id;
+ arena_t *arena;
+
+ item_t *item;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d", cmd, &tux_id, &item_id);
+
+ arena = getCurrentArena();
+
+ item = getItemID(arena->listItem, item_id);
+ tux = getTuxID(arena->listTux, tux_id);
+
+ if( item == NULL)
+ {
+ return;
+ }
+
+ if( tux != NULL )
+ {
+ eventGiveTuxItem(tux, arena->listItem, item);
+ }
+ else
+ {
+ mineExplosion(arena->listItem, item);
+ }
+}
+
+#endif
+
+void proto_send_shot_server(int type, client_t *client, shot_t *p)
+{
+ char msg[STR_PROTO_SIZE];
+ int id = -1;
+
+ assert( p != NULL );
+
+ if( p->author != NULL )
+ {
+ id = p->author->id;
+ }
+
+ sprintf(msg, "shot %d %d %d %d %d %d %d %d\n",
+ p->x, p->y, p->px, p->py, p->position, p->gun, id, p->isCanKillAuthor);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_shot_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int x, y, px, py, position, gun, id, isCanKillAuthor;
+ shot_t *shot;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %d %d %d %d",
+ cmd, &x, &y, &px, &py, &position, &gun, &id, &isCanKillAuthor);
+
+ shot = newShot(x, y, px, py, gun, getTuxID(getCurrentArena()->listTux, id));
+
+ shot->isCanKillAuthor = isCanKillAuthor;
+ shot->position = position;
+
+ if( shot->gun == GUN_LASSER )
+ {
+ transformOnlyLasser(shot);
+ }
+
+ addList(getCurrentArena()->listShot, shot);
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_ping_client()
+{
+ char msg[STR_PROTO_SIZE];
+ sprintf(msg, "ping %d\n", getMyTime());
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_ping_server(client_t *client, char *msg)
+{
+ proto_send_ping_server(PROTO_SEND_ONE, client, msg);
+}
+
+void proto_send_ping_server(int type, client_t *client, char *msg)
+{
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_ping_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ my_time_t currentTime;
+ my_time_t time;
+
+ sscanf(msg, "%s %d", cmd, &time);
+
+ currentTime = getMyTime();
+ printf("lag = %d\n", (currentTime-time));
+ setLagServer((currentTime-time));
+}
+
+#endif
+
+void proto_send_end_server(int type, client_t *client)
+{
+ char msg[STR_PROTO_SIZE];
+ strcpy(msg, "end\n");
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_end_client(char *msg)
+{
+ assert( msg != NULL );
+
+ setWorldEnd();
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_end_client()
+{
+ char msg[STR_PROTO_SIZE];
+ strcpy(msg, "end\n");
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_end_server(client_t *client, char *msg)
+{
+ assert( msg != NULL );
+ assert( client != NULL );
+
+ client->status = NET_STATUS_ZOMBIE;
+}
+