Commit ce6a0f85 authored by Jonathan Michalon's avatar Jonathan Michalon
Browse files

Cleaned server: fixed warnings and dropped clientmain test

parent fedb066d
bin_PROGRAMS = ovccserver ovccclient bin_PROGRAMS = ovccserver
ovccserver_CPPFLAGS = -DG_LOG_DOMAIN=\"OVCCServer\" ovccserver_CPPFLAGS = -DG_LOG_DOMAIN=\"OVCCServer\"
...@@ -8,11 +8,3 @@ ovccserver_VALAFLAGS = $(OVCCSERVER_VALAFLAGS) --thread ...@@ -8,11 +8,3 @@ ovccserver_VALAFLAGS = $(OVCCSERVER_VALAFLAGS) --thread
ovccserver_SOURCES = client.vala \ ovccserver_SOURCES = client.vala \
server.vala \ server.vala \
main.vala main.vala
ovccclient_CPPFLAGS = -DG_LOG_DOMAIN=\"OVCCClient\"
ovccclient_CFLAGS = $(OVCCSERVER_CFLAGS)
ovccclient_LDADD = $(OVCCSERVER_LIBS)
ovccclient_VALAFLAGS = $(OVCCSERVER_VALAFLAGS) --thread
ovccclient_SOURCES = client.vala \
clientmain.vala \
server.vala
/*
*
* Copyright (C) 2011 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
using OVCC.Network;
class MClient: Client
{
protected SocketClient sockclient;
construct
{
sockclient = new SocketClient ();
}
public MClient ()
{
}
public new bool connect (SocketConnectable conn)
throws Error
{
return base.connect (sockclient.connect (conn));
}
}
public static int main (string[] args)
{
string name = "Unnamed client";
string host = "localhost";
if (args.length > 1) {
name = args[1];
}
if (args.length > 2) {
host = args[2];
}
var client = new MClient ();
client.connect (NetworkAddress.parse (host, 0xdead));
//client.receive ().handle (null, client);
client.send (new WelcomeMessage ("Hello"));
client.send (new WelcomeMessage ("I'm %s".printf (name)));
client.send (new DisconnectMessage ());
//client.disconnect ();
return 0;
}
...@@ -34,12 +34,16 @@ public static int main (string[] args) ...@@ -34,12 +34,16 @@ public static int main (string[] args)
if (args.length > 2) { if (args.length > 2) {
port = (uint16)int.parse (args[2]); port = (uint16)int.parse (args[2]);
} }
var loop = new MainLoop (null, false); try {
var server = new Server (name, port); var loop = new MainLoop (null, false);
server.stopped.connect (() => loop.quit ()); var server = new Server (name, port);
server.start (); server.stopped.connect (() => loop.quit ());
loop.run (); server.start ();
loop.run ();
} catch (Error e) {
critical ("Could not start server: %s", e.message);
}
return 0; return 0;
} }
...@@ -93,6 +93,7 @@ public class Server: ThreadedSocketService ...@@ -93,6 +93,7 @@ public class Server: ThreadedSocketService
} }
private bool handle_login (LoginMessage msg, Client client) private bool handle_login (LoginMessage msg, Client client)
throws Error
{ {
bool ok = true; bool ok = true;
if (msg.status != LoginMessage.State.QUERY) { if (msg.status != LoginMessage.State.QUERY) {
...@@ -132,6 +133,7 @@ public class Server: ThreadedSocketService ...@@ -132,6 +133,7 @@ public class Server: ThreadedSocketService
} }
private bool handle_join (JoinMessage msg, Client client) private bool handle_join (JoinMessage msg, Client client)
throws Error
{ {
Game? table = pick_open_table (); Game? table = pick_open_table ();
...@@ -193,13 +195,22 @@ public class Server: ThreadedSocketService ...@@ -193,13 +195,22 @@ public class Server: ThreadedSocketService
} }
switch (msg.message_type) { switch (msg.message_type) {
case MessageType.LOGIN: case MessageType.LOGIN:
bool logged;
debug ("Login for '%s' with '%s'", (msg as LoginMessage).login, debug ("Login for '%s' with '%s'", (msg as LoginMessage).login,
(msg as LoginMessage).password); (msg as LoginMessage).password);
handle_login ((msg as LoginMessage), client); try {
handle_login ((msg as LoginMessage), client);
} catch (Error e) {
/* FIXME send error message */
warning ("Problems handling a client login... left in unknown state");
}
break; break;
case MessageType.JOIN: case MessageType.JOIN:
handle_join (msg as JoinMessage, client); try {
handle_join (msg as JoinMessage, client);
} catch (Error e) {
/* FIXME send error message */
warning ("Problems handling a client join... left in unknown state");
}
break; break;
case MessageType.SIGNAL: case MessageType.SIGNAL:
client.signal_handle.emit_received (msg as SignalMessage); client.signal_handle.emit_received (msg as SignalMessage);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment