--- a/src/proto2/NetworkClient.cc Sat Nov 08 20:34:14 2008 +0000
+++ b/src/proto2/NetworkClient.cc Sat Nov 08 21:25:56 2008 +0000
@@ -1,8 +1,7 @@
#include "NetworkClient.hh"
-
-// XXX: replace logging
-#include <iostream>
+#include "Engine.hh"
+#include "Logger.hh"
NetworkClient::NetworkClient (GameState &state, const CL_IPAddress &connect_to) :
NetworkCore(state), server(netsession.connect(connect_to)) {
@@ -16,28 +15,22 @@
void NetworkClient::on_create_object (CL_NetObject_Client &obj, int msg_type, CL_NetPacket &pkt) {
switch (msg_type) {
case NETMSG_SERVER_HELLO:
- std::cout << "INFO [client.on_create_object] NETMSG_SERVER_HELLO" << std::endl;
-
on_server_hello(obj, pkt);
break;
case NETMSG_PLAYER_INFO:
- std::cout << "INFO [client.on_create_object] NETMSG_PLAYER_INFO" << std::endl;
-
on_player_info(obj, pkt);
break;
case NETMSG_PLAYER_JOIN:
- std::cout << "INFO [client.on_create_object] NETMSG_PLAYER_JOIN" << std::endl;
-
on_player_join(obj, pkt);
break;
default:
- std::cerr << "WARN [client.on_create_object] unknown msg_type=" << msg_type << std::endl;
+ Engine::log(WARN, "client.on_create_object") << "unknown msg_type=" << msg_type << " for obj=" << obj;
}
}
@@ -45,8 +38,10 @@
// read the packet
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
+
+ Coordinate initial_position(x, y);
- Coordinate initial_position(x, y);
+ Engine::log(INFO, "client.on_server_hello") << "obj=" << obj << ", pos=" << initial_position;
// create the LocalPlayer object
NetworkClientLocalPlayer *player = new NetworkClientLocalPlayer(*this, obj, initial_position);
@@ -59,8 +54,10 @@
// read the packet
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
-
+
Coordinate initial_position(x, y);
+
+ Engine::log(INFO, "client.on_player_info") << "obj=" << obj << ", pos=" << initial_position;
// create the LocalPlayer object
NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, initial_position);
@@ -77,6 +74,8 @@
Coordinate initial_position(x, y);
+ Engine::log(INFO, "client.on_player_join") << "obj=" << obj << ", pos=" << initial_position;
+
// create the RemotePlayer object
NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, initial_position);
@@ -89,7 +88,8 @@
state.removePlayer(player);
// delete
- delete player;
+ // XXX: leak because deleting the slot while it's being called breaks ClanLib
+ // delete player;
}
NetworkClientLocalPlayer::NetworkClientLocalPlayer (NetworkClient &client, CL_NetObject_Client &obj, Coordinate initial_position) :
@@ -97,7 +97,6 @@
// receive messages
slots.connect(obj.sig_received_message(NETMSG_PLAYER_POSITION), this, &NetworkClientLocalPlayer::on_position);
-
}
void NetworkClientLocalPlayer::move (PositionDelta d) {
@@ -111,8 +110,12 @@
void NetworkClientLocalPlayer::on_position (CL_NetPacket &pkt) {
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
+
+ Coordinate pos (x, y);
+
+ Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", pos=" << pos;
- updatePosition(Coordinate(x, y));
+ updatePosition(pos);
}
NetworkClientRemotePlayer::NetworkClientRemotePlayer (NetworkClient &client, CL_NetObject_Client &obj, Coordinate initial_position) :
@@ -120,18 +123,25 @@
// receive messages
slots.connect(obj.sig_received_message(NETMSG_PLAYER_POSITION), this, &NetworkClientRemotePlayer::on_position);
+ slots.connect(obj.sig_received_message(NETMSG_PLAYER_QUIT), this, &NetworkClientRemotePlayer::on_quit);
}
void NetworkClientRemotePlayer::on_position (CL_NetPacket &pkt) {
uint32_t x = pkt.input.read_uint32();
uint32_t y = pkt.input.read_uint32();
- updatePosition(Coordinate(x, y));
+ Coordinate pos (x, y);
+
+ Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", pos=" << pos;
+
+ updatePosition(pos);
}
void NetworkClientRemotePlayer::on_quit (CL_NetPacket &pkt) {
// pkt is empty
(void) pkt;
+ Engine::log(INFO, "client_player.on_quit") << "obj=" << obj;
+
client.player_quit(this);
}