Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* master server ping, containing server name, num of players, num of…

… clients, num of creatures. disabled by default.

 * changed real_time to return seconds instead of microseconds.
 * moved bots to contrib



git-svn-id: http://infon.googlecode.com/svn/trunk@198 8171fb75-e542-0410-96e4-03d5dd800671
  • Loading branch information...
commit d91d2c6bc927a28db8d6695bdad4f76fe259e814 1 parent bec516e
@dividuum authored
View
15 Makefile
@@ -161,16 +161,23 @@ win32-client-dist: $(INFON_EXECUTABLE) $(SDL_RENDERER) $(GL_RENDERER)
upx -9 --all-methods $(INFON_EXECUTABLE)
upx -9 --all-methods $(SDL_RENDERER)
upx -9 --all-methods $(GL_RENDERER)
- zip infon-win32-r$(REVISION).zip README.txt $^ gfx/*.fnt gfx/*.png gfx/*.bmp gfx/*.mdl bots/*.lua bots/*.txt
+ zip infon-win32-r$(REVISION).zip \
+ README.txt $^ gfx/*.fnt gfx/*.png gfx/*.bmp gfx/*.mdl \
+ contrib/bots/*.lua contrib/bots/*.txt
linux-client-dist: $(INFON_EXECUTABLE) $(SDL_RENDERER) $(NULL_RENDERER) $(GL_RENDERER)
strip $^
- tar cfvz infon-linux-i386-r$(REVISION).tgz README.txt $^ gfx/*.fnt gfx/*.png gfx/*.bmp gfx/*.mdl bots/*.lua bots/*.txt
+ tar cfvz infon-linux-i386-r$(REVISION).tgz \
+ README.txt $^ gfx/*.fnt gfx/*.png gfx/*.bmp gfx/*.mdl \
+ contrib/bots/*.lua contrib/bots/*.txt
linux-server-dist: $(INFOND_EXECUTABLE) infond-wrapper
- tar cfvz infond-linux-i386-r$(REVISION).tgz README.txt $(INFOND_EXECUTABLE) infond-wrapper $(INFOND_EXECUTABLE)-static *.lua level/*.lua rules/*.lua api/*.lua libs/*.lua bots/*.lua bots/*.txt
+ tar cfvz infond-linux-i386-r$(REVISION).tgz \
+ README.txt $(INFOND_EXECUTABLE) infond-wrapper $(INFOND_EXECUTABLE)-static \
+ *.lua level/*.lua rules/*.lua api/*.lua libs/*.lua \
+ contrib/bots/*.lua contrib/bots/*.txt
-$(INFOND_EXECUTABLE): infond.o server.o listener.o map.o path.o misc.o packet.o player.o world.o creature.o scroller.o game.o
+$(INFOND_EXECUTABLE): infond.o server.o listener.o map.o path.o misc.o packet.o player.o world.o creature.o scroller.o game.o pinger.o
$(CC) $^ $(LDFLAGS) -o $@
$(CC) $^ $(LDFLAGS) -static -o $@-static
View
8 config.lua
@@ -93,7 +93,7 @@ debugger = false
-- Things to do once after the first game started
--
-- function autoexec()
--- start_bot{ source = "bots/easybot.lua",
+-- start_bot{ source = "contrib/bots/easybot.lua",
-- name = "foo",
-- password = "secret",
-- api = "state" }
@@ -107,4 +107,10 @@ debugger = false
-- function check_name_password(user, pass)
-- end
+-- Uncomment the following lines to announce your
+-- server to the Master Server at infon.dividuum.de.
+-- This will send a tiny UDP packet every minute.
+--
+-- master_ip = '217.28.96.154' -- infon.dividuum.de
+-- servername = 'An Infon Server'
View
0  bots/BlueloopV00.lua → contrib/bots/BlueloopV00.lua
File renamed without changes
View
0  bots/BlueloopV01.lua → contrib/bots/BlueloopV01.lua
File renamed without changes
View
0  bots/GuardBot.lua → contrib/bots/GuardBot.lua
File renamed without changes
View
0  bots/README.txt → contrib/bots/README.txt
File renamed without changes
View
0  bots/easybot.lua → contrib/bots/easybot.lua
File renamed without changes
View
0  bots/gravity-bot-working.lua → contrib/bots/gravity-bot-working.lua
File renamed without changes
View
0  bots/queener.lua → contrib/bots/queener.lua
File renamed without changes
View
0  bots/sissy-bot-menu.lua → contrib/bots/sissy-bot-menu.lua
File renamed without changes
View
0  bots/sissy-bot.lua → contrib/bots/sissy-bot.lua
File renamed without changes
View
0  bots/stupibot.lua → contrib/bots/stupibot.lua
File renamed without changes
View
0  bots/stupibot2.lua → contrib/bots/stupibot2.lua
File renamed without changes
View
0  bots/unbug.lua → contrib/bots/unbug.lua
File renamed without changes
View
12 creature.c
@@ -35,6 +35,8 @@
#include "misc.h"
static creature_t creatures[MAXCREATURES];
+static int num_creatures = 0;
+
#define CREATURE_USED(creature) (!!((creature)->player))
#define HASHTABLE_SIZE ((MAXCREATURES) * 4)
@@ -896,6 +898,8 @@ creature_t *creature_spawn(player_t *player, creature_t *parent, int x, int y, c
if (!creature)
return NULL;
+ num_creatures++;
+
memset(creature, 0, sizeof(creature_t));
creature->vm_id = next_free_vm_id++;
@@ -936,6 +940,8 @@ void creature_kill(creature_t *creature, creature_t *killer) {
path_delete(creature->path);
creature->player = NULL;
+ num_creatures--;
+
const int hash = HASHVALUE(creature->vm_id);
creature_t *tmp = creature_hash[hash];
if (tmp == creature) {
@@ -1017,13 +1023,17 @@ void creature_to_network(creature_t *creature, int dirtymask, client_t *client)
server_send_packet(&packet, client);
}
+int creature_num_creatures() {
+ return num_creatures;
+}
+
void creature_init() {
for (int i = 0; i < MAXCREATURES; i++) {
creature_t *creature = &creatures[i];
creature->player = NULL;
}
-
next_free_vm_id = 0;
+ assert(num_creatures == 0);
}
void creature_shutdown() {
View
1  creature.h
@@ -95,6 +95,7 @@ int creature_attack_distance(const creature_t *creature);
void creature_kill_all_players_creatures(player_t *player);
void creature_moveall(int delta);
+int creature_num_creatures();
/* Network */
void creature_send_initial_update(client_t *client);
View
7 game.c
@@ -32,7 +32,8 @@
#include "misc.h"
static int should_end_game = 0;
-static struct timeval server_start, game_start;
+static struct timeval game_start;
+static time_t server_start;
static char intermission[256] = {0};
static int realtime = 1;
@@ -155,7 +156,7 @@ static int luaHexDecode(lua_State *L) {
}
void game_init() {
- gettimeofday(&server_start, NULL);
+ server_start = time(NULL);
lua_register(L, "game_end", luaGameEnd);
lua_register(L, "game_time", luaGameTime);
@@ -235,7 +236,7 @@ void game_one_game() {
lasttick = tick;
// Realtime update
- real_time = get_tick(&server_start);
+ real_time = time(NULL) - server_start;
// GC
lua_gc(L, LUA_GCSTEP, 1);
View
2  infon.c
@@ -164,7 +164,7 @@ int main(int argc, char *argv[]) {
screen_saver_start:
#endif
- srand(time(0));
+ srand(time(NULL));
gettimeofday(&start, NULL);
if (!renderer_init(renderer))
View
7 infond.c
@@ -45,8 +45,9 @@
lua_State *L;
-int real_time = 0;
-int game_time = 0;
+int real_time = 0; // Seconds since server start
+int game_time = 0; // Microseconds since game start
+
int game_paused = 0;
int game_exit = 0;
@@ -66,7 +67,7 @@ int main(int argc, char *argv[]) {
signal(SIGINT, sighandler);
signal(SIGPIPE, SIG_IGN);
- srand(time(0));
+ srand(time(NULL));
L = luaL_newstate();
luaL_openlibs(L);
View
6 infond.lua
@@ -244,12 +244,12 @@ end
function Client:rate_limit(action, every)
local time, last = real_time(), self.last_action[action]
- if not last or time > last + every then
+ if not last or last + every <= time then
self.last_action[action] = real_time()
return true
else
- self:writeln(string.format("%s too fast. please wait %.1fs...",
- action, (every - (time - last)) / 1000))
+ self:writeln(string.format("%s too fast. please wait %d seconds...",
+ action, (every - (time - last))))
return false
end
end
View
1  packet.h
@@ -45,6 +45,7 @@ __attribute__((packed))
#define PACKET_ROUND 9
#define PACKET_INTERMISSION 10
#define PACKET_WELCOME_MSG 32
+#define PACKET_MASTER_PING 253
#define PACKET_START_COMPRESS 254
#define PACKET_HANDSHAKE 255
uint8_t data[256];
View
58 pinger.c
@@ -0,0 +1,58 @@
+/*
+
+ Copyright (c) 2006 Florian Wesch <fw@dividuum.de>. All Rights Reserved.
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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
+
+*/
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "packet.h"
+
+void ping_master(const char *master_addr, int port, const char *servername,
+ int clients, int players, int creatures)
+{
+ struct sockaddr_in master;
+ socklen_t addrlen = sizeof(struct sockaddr_in);
+
+ size_t namelen = strlen(servername);
+ if (namelen > 32) namelen = 32;
+
+ memset(&master, 0, sizeof(struct sockaddr_in));
+ master.sin_family = AF_INET;
+ master.sin_addr.s_addr = inet_addr(master_addr);
+ master.sin_port = htons(port);
+
+ int sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0)
+ return;
+
+ packet_t packet;
+ packet_init(&packet, PACKET_MASTER_PING);
+ packet_write08(&packet, clients);
+ packet_write08(&packet, players);
+ packet_write08(&packet, creatures);
+ packet_writeXX(&packet, servername, namelen);
+ packet.len = packet.offset;
+ sendto(sock, &packet, PACKET_HEADER_SIZE + packet.len, 0,
+ (struct sockaddr *)&master, addrlen);
+ close(sock);
+}
View
27 pinger.h
@@ -0,0 +1,27 @@
+/*
+
+ Copyright (c) 2006 Florian Wesch <fw@dividuum.de>. All Rights Reserved.
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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
+
+*/
+
+#ifndef PINGER_H
+#define PINGER_H
+
+void ping_master(const char *master_addr, int port, const char *servername,
+ int clients, int players, int creatures);
+
+#endif
View
10 player.c
@@ -42,6 +42,8 @@
#define PLAYER_USED(player) (!!((player)->L))
static player_t players[MAXPLAYERS];
+static int num_players = 0;
+
static player_t *king_player = NULL;
void player_change_score(player_t *player, int scoredelta, const char *reason) {
@@ -734,6 +736,8 @@ player_t *player_create(const char *name, const char *pass, const char *highleve
player_to_network(player, PLAYER_DIRTY_ALL, SEND_BROADCAST);
+ num_players++;
+
player_on_created(player);
return player;
@@ -755,6 +759,8 @@ void player_destroy(player_t *player) {
lua_close(player->L);
player->L = NULL;
+
+ num_players--;
player_to_network(player, PLAYER_DIRTY_ALIVE, SEND_BROADCAST);
}
@@ -1220,6 +1226,10 @@ static int luaPlayerExecute(lua_State *L) {
return 1;
}
+int player_num_players() {
+ return num_players;
+}
+
void player_init() {
memset(players, 0, sizeof(players));
View
1  player.h
@@ -92,6 +92,7 @@ void player_sync();
void player_is_king_of_the_hill(player_t *player, int delta);
void player_there_is_no_king();
player_t *player_king();
+int player_num_players();
/* Network */
void player_send_initial_update(client_t *client);
View
31 server.c
@@ -46,11 +46,15 @@
#include "misc.h"
#include "game.h"
#include "creature.h"
+#include "pinger.h"
#define CLIENT_USED(client) ((client)->in_buf)
static client_t *guiclients = NULL;
+
static client_t clients[MAXCLIENTS];
+static int num_clients = 0;
+
static client_t *output_client = NULL;
static int traffic = 0;
@@ -119,6 +123,8 @@ client_t *server_accept(int fd, const char *address) {
client->next_gui = NULL;
client->prev_gui = NULL;
+ num_clients++;
+
// Annehmen
lua_pushliteral(L, "on_client_accepted");
lua_rawget(L, LUA_GLOBALSINDEX);
@@ -362,6 +368,8 @@ void server_destroy(client_t *client, const char *reason) {
guiclients = client->next_gui;
}
}
+
+ num_clients--;
#ifndef NO_CONSOLE_CLIENT
if (fd != STDIN_FILENO)
@@ -518,6 +526,22 @@ static int luaSetupListener(lua_State *L) {
return 1;
}
+static int luaPingMaster(lua_State *L) {
+ ping_master(luaL_checkstring(L, 1), luaL_checklong(L, 2),
+ luaL_checkstring(L, 3),
+ server_num_clients(),
+ player_num_players(),
+ creature_num_creatures());
+ return 0;
+}
+
+static int luaServerInfo(lua_State *L) {
+ lua_pushnumber(L, server_num_clients());
+ lua_pushnumber(L, player_num_players());
+ lua_pushnumber(L, creature_num_creatures());
+ return 3;
+}
+
void server_tick() {
lua_set_cycles(L, 0xFFFFFF);
@@ -543,6 +567,10 @@ void server_tick() {
}
}
+int server_num_clients() {
+ return num_clients;
+}
+
void server_init() {
#ifdef WIN32
WSADATA wsa;
@@ -564,8 +592,9 @@ void server_init() {
lua_register(L, "cprint", luaClientPrint);
lua_register(L, "server_start_writer", luaStartFileWriter);
lua_register(L, "server_get_traffic", luaGetTraffic);
+ lua_register(L, "server_ping_master", luaPingMaster);
+ lua_register(L, "server_info", luaServerInfo);
lua_register(L, "setup_listener", luaSetupListener);
-
}
void server_game_end() {
View
17 server.h
@@ -66,20 +66,21 @@ typedef struct client_s {
} client_t;
client_t *server_accept(int fd, const char *address);
-void server_writeto(client_t *client, const void *data, size_t size);
-void server_writeto_all_gui_clients(const void *data, size_t size);
-void server_destroy(client_t *client, const char *reason);
+void server_writeto(client_t *client, const void *data, size_t size);
+void server_writeto_all_gui_clients(const void *data, size_t size);
+void server_destroy(client_t *client, const char *reason);
client_t *client_get_checked_lua(lua_State *L, int idx);
-void server_send_packet(packet_t *packet, client_t *client);
+void server_send_packet(packet_t *packet, client_t *client);
client_t *server_start_demo_writer(const char *demoname, int one_game);
-void server_tick();
+void server_tick();
+int server_num_clients();
-void server_init();
-void server_game_end();
-void server_shutdown();
+void server_init();
+void server_game_end();
+void server_shutdown();
#endif
View
29 server.lua
@@ -23,7 +23,7 @@
-----------------------------------------------------------
function Client:joinmenu()
- if not self:rate_limit("joining", 3000) then return end
+ if not self:rate_limit("joining", 3) then return end
self:writeln("------------------------------")
local numplayers = 0
@@ -92,7 +92,7 @@ function Client:partmenu()
end
function Client:namemenu()
- if not self:rate_limit("changing name", 1000) then return end
+ if not self:rate_limit("changing name", 2) then return end
self:write("Player Name: ")
if not self:set_name(self:readln()) then
@@ -101,7 +101,7 @@ function Client:namemenu()
end
function Client:colormenu()
- if not self:rate_limit("changing color", 1000) then return end
+ if not self:rate_limit("changing color", 2) then return end
self:write("color (0 - 255): ")
local color = self:readln()
@@ -202,7 +202,7 @@ function Client:shell()
self:writeln("password must be set in config.lua")
return
end
- if not self:rate_limit("entering the shell", 5000) then return end
+ if not self:rate_limit("entering the shell", 5) then return end
self:write("password: ")
ok = self:readln() == config.debugpass
end
@@ -278,7 +278,7 @@ function Client:nokick()
if not config.nokickpass or config.nokickpass == "" then
self:writeln("no kick mode disabled. sorry")
else
- if not self:rate_limit("no kicking", 3000) then return end
+ if not self:rate_limit("no kicking", 3) then return end
self:write("enter nokick password: ")
if self:readln() == config.nokickpass then
player_set_no_client_kick_time(self:get_player(), 0)
@@ -290,11 +290,13 @@ function Client:nokick()
end
function Client:info()
+ local clients, players, creatures = server_info()
self:writeln("-------------------------------------------------")
self:writeln("Server Information")
self:writeln("-------------------+-----------------------------")
+ self:writeln("server name | " .. (config.servername or 'default server'))
self:writeln("version | " .. GAME_NAME)
- self:writeln("uptime | " .. string.format("%ds", real_time() / 1000))
+ self:writeln("uptime | " .. string.format("%ds", real_time()))
self:writeln("cpu usage | " .. os.clock() .. "s")
self:writeln("memory | " .. string.format("%d", collectgarbage("count")) .. "kb")
self:writeln("traffic | " .. server_get_traffic())
@@ -305,6 +307,10 @@ function Client:info()
self:writeln("played maps | " .. stats.num_maps)
self:writeln("code executions | " .. stats.num_exec)
self:writeln("-------------------+------------------------------")
+ self:writeln("current players | " .. players)
+ self:writeln("current clients | " .. clients)
+ self:writeln("current creatures | " .. creatures)
+ self:writeln("-------------------+------------------------------")
local w, h = world.level_size()
self:writeln("rules | " .. config.rules)
self:writeln("map | " .. map .. " (" .. w .. "x" .. h .. ")")
@@ -502,13 +508,24 @@ function ServerMain()
scroller_add("Welcome to " .. GAME_NAME .. "!")
local info_time = game_time()
+ local ping_time = -10000
while true do
+ -- Add info message to the scroller
if game_time() > info_time + 10000 then
info_time = game_time()
if config.join_info and config.join_info ~= "" then
scroller_add(config.join_info)
end
end
+
+ -- Announce this server to the master server.
+ if config.master_ip and real_time() > ping_time + 60 then
+ ping_time = real_time()
+ server_ping_master(config.master_ip,
+ config.master_port or 1234,
+ config.servername or 'default server')
+ end
+
coroutine.yield()
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.