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

New message type LoginMessage

Added LoginMessage class with login and password.
Used it at connection in libovccclient and in server.
parent dfab8f7a
......@@ -21,6 +21,7 @@ libovcc_la_SOURCES = board.vala \
ovccnetworkmessage.vala \
ovccnetworkemptymessage.vala \
ovccnetworkstringmessage.vala \
ovccnetworkloginmessage.vala \
ovccnetworkdisconnectmessage.vala \
ovccnetworkwelcomemessage.vala \
ovccnetworkerrormessage.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/>.
*
*/
/**
* Login message with login and password
*/
public class OVCC.Network.LoginMessage : StringMessage
{
public override MessageType message_type { get { return MessageType.LOGIN; } }
public string login { get; set; default = null; }
public string password { get; set; default = null; }
public LoginMessage (string login, string password)
{
Object (login: login, password: password);
}
public override bool serialize (DataOutputStream stream,
Cancellable? cancel = null)
throws Error
{
/* FIXME separator */
message = login + "|" + password;
return base.serialize(stream, cancel);
}
public override bool deserialize (DataInputStream stream,
Cancellable? cancel = null)
throws Error
{
base.deserialize (stream, cancel);
string[] fields = message.split ("|");
if (fields == null || fields.length != 2) {
throw new MessageError.MALFORMED_MESSAGE ("Message should have two fields");
}
login = fields[0];
password = fields[1];
return true;
}
}
......@@ -41,6 +41,7 @@ namespace OVCC.Network
{
ERROR,
WELCOME,
LOGIN,
DISCONNECT,
INVALID
}
......@@ -51,6 +52,7 @@ namespace OVCC.Network
private static Type[] message_types = {
typeof (ErrorMessage),
typeof (WelcomeMessage),
typeof (LoginMessage),
typeof (DisconnectMessage)
};
......
......@@ -55,6 +55,8 @@ namespace OVCCClient
warning ("Trying to connect: %s", e.message);
throw new ServerError.FAILED ("Cannot connect to server");
}
/* login */
send_message (new LoginMessage (player.nick, ""));
/* ... */
return true;
}
......
......@@ -88,6 +88,10 @@ public class Server: ThreadedSocketService
debug (" --- %s", (msg as StringMessage).message);
}
switch (msg.message_type) {
case MessageType.LOGIN:
debug ("Login with '%s' and '%s'", (msg as LoginMessage).login,
(msg as LoginMessage).password);
break;
case MessageType.DISCONNECT: running = false; break;
}
}
......
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