...
 
Commits (6)
......@@ -5,6 +5,8 @@
# ------------------------------------
AC_DEFUN([OVCC_VALADOC_CHECK],
[
AC_REQUIRE([AC_PROG_SED])
AC_ARG_ENABLE([valadoc],
[AS_HELP_STRING([--enable-valadoc],
[Whether to build the documentation @<:@default=auto@:>@])],
......@@ -16,7 +18,7 @@ AC_DEFUN([OVCC_VALADOC_CHECK],
[AC_PATH_PROG([VALADOC], [valadoc], [NONE])
AS_IF([test "x$VALADOC" != xNONE],
[AC_MSG_CHECKING([whether $VALADOC is at least version $1])
ovcc__valadoc_version=`$VALADOC --version | sed 's/Valadoc *//'`
ovcc__valadoc_version=`$VALADOC --version | $SED 's/Valadoc *//'`
AS_VERSION_COMPARE([$1], ["$ovcc__valadoc_version"],
[have_valadoc=yes],
[have_valadoc=yes],
......
......@@ -4,7 +4,7 @@ VALADOC_SRCDIR = $(top_srcdir)/src
VALADOC_FILES = $(wildcard $(VALADOC_SRCDIR)/*.vala) \
$(wildcard $(VALADOC_SRCDIR)/*/*.vala)
VALADOC_FLAGS = $(LIBOVCC_VALAFLAGS) --pkg=hack
VALADOC_LIB = $(VALADOC_SRCDIR)/.libs/libovcc.so
VALADOC_LIB = $(top_builddir)/src/.libs/libovcc.so
VALADOC_CHEADER = $(VALADOC_SRCDIR)/ovcc.h
include $(top_srcdir)/build/ovcc-valadoc.make
......@@ -41,6 +41,8 @@ test_CFLAGS = $(LIBOVCC_CFLAGS)
test_LDADD = $(LIBOVCC_LIBS) libovcc.la -lpthread
test_SOURCES = test.c
test.c: ovcc.h
$(srcdir)/ovcc.h $(srcdir)/ovcc.vapi: libovcc_la_vala.stamp
$(lib_LTLIBRARIES): stamp-hack
......@@ -48,12 +50,12 @@ $(lib_LTLIBRARIES): stamp-hack
stamp-hack: ovcc.h ovcc.vapi
(f=`mktemp $@.XXXXXXXXXX`; trap -- "rm -f '$$f'" EXIT QUIT TERM; \
ovcc_h=ovcc.h; [ -f "$$ovcc_h" ] || ovcc_h="$(srcdir)/$$ovcc_h"; \
cat $(srcdir)/hack.h "$$ovcc_h" | sed '/<hack.h>/d'> "$$f" && \
cat $(srcdir)/hack.h "$$ovcc_h" | $(SED) '/<hack.h>/d'> "$$f" && \
(echo "/* this file is auto-generated, do not modify it (XXX: generated by valac) */" && \
cat "$$f") > ovcc.h)
(f=`mktemp $@.XXXXXXXXXX`; trap -- "rm -f '$$f'" EXIT QUIT TERM; \
ovcc_vapi=ovcc.vapi; [ -f "$$ovcc_vapi" ] || ovcc_vapi="$(srcdir)/$$ovcc_vapi"; \
cat $(srcdir)/hack.vapi "$$ovcc_vapi" | sed 's~"\(hack\|ovcc\).h"~"ovcc/ovcc.h"~g' > "$$f" && \
cat $(srcdir)/hack.vapi "$$ovcc_vapi" | $(SED) 's~"\(hack\|ovcc\).h"~"ovcc/ovcc.h"~g' > "$$f" && \
(echo "/* this file is auto-generated, do not modify it (XXX: generated by valac) */" && \
cat "$$f") > ovcc.vapi)
touch $@
......@@ -34,6 +34,7 @@ public class OVCC.Network.LoginMessage : VariantMessage
{
QUERY,
OK,
MALFORMED_MESSAGE,
ALREADY_EXISTS,
MISSING_AUTHENTICATION,
UNAUTHORIZED
......
......@@ -5,6 +5,8 @@
# ------------------------------------
AC_DEFUN([OVCC_VALADOC_CHECK],
[
AC_REQUIRE([AC_PROG_SED])
AC_ARG_ENABLE([valadoc],
[AS_HELP_STRING([--enable-valadoc],
[Whether to build the documentation @<:@default=auto@:>@])],
......@@ -16,7 +18,7 @@ AC_DEFUN([OVCC_VALADOC_CHECK],
[AC_PATH_PROG([VALADOC], [valadoc], [NONE])
AS_IF([test "x$VALADOC" != xNONE],
[AC_MSG_CHECKING([whether $VALADOC is at least version $1])
ovcc__valadoc_version=`$VALADOC --version | sed 's/Valadoc *//'`
ovcc__valadoc_version=`$VALADOC --version | $SED 's/Valadoc *//'`
AS_VERSION_COMPARE([$1], ["$ovcc__valadoc_version"],
[have_valadoc=yes],
[have_valadoc=yes],
......
......@@ -2,7 +2,7 @@
VALADOC_MODULE_NAME = LibOVCCClient
VALADOC_SRCDIR = $(top_srcdir)/src
VALADOC_FLAGS = $(LIBOVCCCLIENT_VALAFLAGS)
VALADOC_LIB = $(VALADOC_SRCDIR)/.libs/libovccclient.so
VALADOC_LIB = $(top_builddir)/src/.libs/libovccclient.so
VALADOC_CHEADER = $(VALADOC_SRCDIR)/ovccclient.h
include $(top_srcdir)/build/ovcc-valadoc.make
......@@ -13,8 +13,10 @@ vapi_DATA = ovccclient.vapi
$(lib_LTLIBRARIES): stamp-hack
$(srcdir)/ovccclient.h $(srcdir)/ovccclient.vapi: libovccclient_la_vala.stamp
# hack: add prefix to header filename in VAPI file
stamp-hack: ovccclient.vapi
stamp-hack: $(srcdir)/ovccclient.vapi
$(AM_V_GEN) \
sed -i 's~"\(ovccclient.h\)"~"ovcc/\1"~g' $<
$(SED) -i 's~"\(ovccclient.h\)"~"ovcc/\1"~g' $<
touch $@
......@@ -79,6 +79,14 @@ public class Client: Object
return Message.receive (input, cancel);
}
public bool log_in (string login_p, string password_p)
{
login = login_p;
password = password_p;
return true;
}
public bool join (Game game_p)
{
player = new Player (login);
......
......@@ -95,49 +95,58 @@ public class Server: ThreadedSocketService
}
private bool handle_login (LoginMessage msg, Client client)
throws Error
{
bool ok = true;
debug ("Login tentative for '%s' with '%s'", msg.login, msg.password);
if (msg.status != LoginMessage.State.QUERY) {
critical ("got LoginMessage with status different from QUERY");
return false;
}
/* missing authentication check */
if (msg.password == "") {
/* message state check */
debug ("got LoginMessage with status different from QUERY");
msg.status = LoginMessage.State.MALFORMED_MESSAGE;
} else if (msg.password == "") {
/* empty password not allowed */
debug ("rejecting auth as password is empty");
msg.status = LoginMessage.State.MISSING_AUTHENTICATION;
client.send (msg);
return false;
}
} else {
lock (this.clients) {
/* forbid duplicates */
foreach (Client c in this.clients) {
if (c.login == msg.login) {
ok = false;
debug ("rejecting auth as login already connected");
msg.status = LoginMessage.State.ALREADY_EXISTS;
break;
}
}
/* actual registration */
if (ok) {
debug ("accepting auth for %s", msg.login);
msg.status = LoginMessage.State.OK;
/* already existing name check WARNING: lock needed */
lock (this.clients) {
foreach (Client c in this.clients) {
if (c.login == msg.login) {
ok = false;
debug ("rejecting auth as login already connected");
msg.status = LoginMessage.State.ALREADY_EXISTS;
break;
client.log_in (msg.login, msg.password);
}
}
/* registration */
if (ok) {
debug ("accepting auth for %s", msg.login);
msg.status = LoginMessage.State.OK;
client.login = msg.login;
client.password = msg.password;
}
}
client.send (msg);
try {
client.send (msg);
} catch (Error e) {
warning ("Can't reply to client: %s", e.message);
return false;
}
return ok;
}
private bool handle_join (JoinMessage msg, Client client)
throws Error
{
Game? game = null;
debug ("Game Join tentative for game '%d'", msg.game_index);
if (msg.game_index == -1) {
game = pick_open_game ();
} else {
......@@ -146,37 +155,58 @@ public class Server: ThreadedSocketService
if (game == null || !game.state.is_open ()) {
debug ("Bad game %d, sending fail join message", msg.game_index);
var join = new JoinMessage (msg.game_index);
join.status = JoinMessage.State.FAILED;
client.send (join);
msg.status = JoinMessage.State.FAILED;
} else {
debug ("Accepting game join");
msg.status = JoinMessage.State.OK;
}
try {
client.send (msg);
} catch (Error e) {
warning ("Can't reply to client: %s", e.message);
return false;
}
debug ("Accepting game join");
var join = new JoinMessage (msg.game_index);
join.status = JoinMessage.State.OK;
client.send (join);
client.join (game);
debug ("Sending game data");
var data = new GamedataMessage (client.game.get_stack_ids(),
client.game.get_player_nicks(),
tiles_data, tileset_data);
client.send (data);
if (msg.status == JoinMessage.State.OK) {
client.join (game);
debug ("Sending game data");
var data = new GamedataMessage (client.game.get_stack_ids(),
client.game.get_player_nicks(),
tiles_data, tileset_data);
try {
client.send (data);
} catch (Error e) {
warning ("Can't reply to client: %s", e.message);
return false;
}
}
return true;
}
private bool handle_list_games (ListGamesMessage msg, Client client)
throws Error
{
GameDescription[] list = {};
debug ("A client asked for a list of games, let's reply");
foreach (var t in games) {
list += t.describe ();
}
var data = new ListGamesMessage (list);
client.send (data);
try {
client.send (data);
} catch (Error e) {
warning ("Can't reply to client: %s", e.message);
return false;
}
return true;
}
......@@ -222,35 +252,20 @@ public class Server: ThreadedSocketService
}
switch (msg.message_type) {
case MessageType.LOGIN:
debug ("Login for '%s' with '%s'", (msg as LoginMessage).login,
(msg as LoginMessage).password);
try {
handle_login ((msg as LoginMessage), client);
} catch (Error e) {
/* FIXME send error message */
warning ("Problems handling a client login... left in unknown state");
}
handle_login ((msg as LoginMessage), client);
break;
case MessageType.JOIN:
try {
handle_join (msg as JoinMessage, client);
} catch (Error e) {
/* FIXME send error message */
warning ("Problems handling a client join... left in unknown state");
}
handle_join (msg as JoinMessage, client);
break;
case MessageType.LIST_GAMES:
try {
handle_list_games (msg as ListGamesMessage, client);
} catch (Error e) {
/* FIXME send error message */
warning ("Problems handling a list game action...");
}
handle_list_games (msg as ListGamesMessage, client);
break;
case MessageType.SIGNAL:
client.signal_handle.emit_received (msg as SignalMessage);
break;
case MessageType.DISCONNECT: running = false; break;
case MessageType.DISCONNECT:
running = false;
break;
}
}
lock (this.clients) {
......