Show playerclient.cpp syntax highlighted
/***************************************************************************
playerclient.cpp
-------------------
begin : Wed Jun 9 2004
copyright : (C) 2004 by Brendon Higgins
email : freepop-devel@lists.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <playerclient.h>
#include <client.h>
#include <identity.h>
CL_Signal_v2<const std::string&, PlayerClient*> PlayerClient::mSigNameChange;
CL_Signal_v2<unsigned int, PlayerClient*> PlayerClient::mSigColourChange;
PlayerClient::PlayerClient(CL_InputSource &is):
slot(is.read_int32()),
name(is.read_string()),
colour(is.read_uint32()),
numPeeps(is.read_int32()),
numTowns(is.read_int32()),
numLeaders(is.read_int32()),
local(is.read_bool8()) {
}
PlayerClient::~PlayerClient() {
}
bool PlayerClient::isLocal() const {
return local;
}
int PlayerClient::getSlot() const {
return slot;
}
const std::string& PlayerClient::getName() const {
return name;
}
void PlayerClient::setName(CL_NetComputer& server, const std::string& n) {
CL_NetPacket p = startMessage(Player::Message::NAME_CHANGE);
p.output.write_string(n);
server.send(Network::Channel::ADMIN, p);
}
void PlayerClient::onNameChange(CL_NetPacket& p) {
std::string oldname = name;
name = p.input.read_string();
sigNameChange()(oldname, this);
}
CL_Signal_v2<const std::string&, PlayerClient*>& PlayerClient::sigNameChange() {
return mSigNameChange;
}
unsigned int PlayerClient::getColour() const {
return colour;
}
void PlayerClient::setColour(CL_NetComputer& server, unsigned int c) {
CL_NetPacket p = startMessage(Player::Message::COLOUR_CHANGE);
p.output.write_uint32(c);
server.send(Network::Channel::ADMIN, p);
}
void PlayerClient::onColourChange(CL_NetPacket& p) {
unsigned int oldcolour = colour;
colour = p.input.read_uint32();
sigColourChange()(oldcolour, this);
}
CL_Signal_v2<unsigned int, PlayerClient*>& PlayerClient::sigColourChange() {
return mSigColourChange;
}
void PlayerClient::onMessage(CL_NetPacket& p) {
int t = p.input.read_int32();
if (t == Player::Message::NAME_CHANGE) onNameChange(p);
if (t == Player::Message::COLOUR_CHANGE) onColourChange(p);
}
CL_NetPacket PlayerClient::startMessage(int t) const {
CL_NetPacket p;
p.output.write_uint32(Network::Admin::PLAYER_MESSAGE);
p.output.write_int32(getSlot());
p.output.write_int32(t);
return p;
}
See more files for this project here