Commit badf5d00 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Merge branch 'composed-tiles' of ssh://git.tuxfamily.org/gitroot/chalmion/ovcc into composed-tiles

parents 4fb6bfd0 e6c71880
......@@ -63,11 +63,11 @@ namespace OVCC.Network
output = output_p;
game_object.player_added.connect ((p) => {
send_to_peer (SignalType.PLAYER_ADDED, {1, 2});
send_to_peer (SignalType.PLAYER_ADDED, "s", p.nick);
});
}
private bool send_to_peer (SignalType s, uint8[] data)
private bool send_to_peer (SignalType s, string format, ...)
{
if (ignore_next[s] > 0) {
ignore_next[s]--;
......@@ -76,7 +76,8 @@ namespace OVCC.Network
SignalMessage msg = new SignalMessage ();
msg.stype = s;
msg.data = data;
var ap = va_list();
msg.build_data_va (format, &ap);
debug ("Transmitting signal %s", s.to_string());
try {
msg.send (output);
......@@ -91,9 +92,11 @@ namespace OVCC.Network
debug ("Received signal %s", msg.stype.to_string());
switch (msg.stype) {
case SignalType.PLAYER_ADDED:
debug ("Adding player %s", "new");
ignore_next[SignalType.PLAYER_ADDED]++;
game_object.add_player (new Player("new"));
string nick;
msg.parse_data ("s", out nick);
debug ("Adding new player %s", nick);
game_object.add_player (new Player(nick));
break;
}
return true;
......@@ -105,7 +108,7 @@ namespace OVCC.Network
public override MessageType message_type { get { return MessageType.SIGNAL; } }
public SignalType stype { get; set; default = 0; }
public uint8[] data { get; set; default = null; }
public uint8[] data { get; private set; default = null; }
public override bool serialize (DataOutputStream stream,
Cancellable? cancel = null)
......@@ -124,5 +127,30 @@ namespace OVCC.Network
return true;
}
public void build_data_va (string format,
va_list *ap)
{
Variant v = new Variant.va (format, null, ap);
this.data = new uint8[v.get_size()];
v.store (this.data);
}
public void build_data (string format,
...)
{
var ap = va_list();
build_data_va (format, &ap);
}
public void parse_data (string format,
...)
{
var ap = va_list ();
Variant v = Variant.new_from_data<Object> (new VariantType(format), data, false, this);
v.get_va (format, null, &ap);
}
}
}
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