boost::asio::placeholders::error));
if (on_receive_) {
- (*on_receive_)(ConnectionSucceeded());
+ // (*on_receive_)(ConnectionSucceeded());
}
} else {
if (on_receive_) {
- (*on_receive_)(ConnectionFailed());
+ // (*on_receive_)(ConnectionFailed());
}
}
}
return session_;
}
-// コネクションの確立に成功
-ConnectionSucceeded::ConnectionSucceeded() :
- Command(header::ConnectionSucceeded, "")
-{
-
-}
-
-ConnectionFailed::ConnectionFailed() :
- Command(header::ConnectionFailed, "")
-{
-
-}
-
FatalConnectionError::FatalConnectionError() :
Command(header::FatalConnectionError, "")
{
body_ = Utils::Serialize(user_id);
}
-ClientReceiveChatMessage::ClientReceiveChatMessage(unsigned int user_id,
- const std::string& time_string,
- const std::string& msg) :
- Command(header::ClientReceiveChatMessage, Utils::Serialize<unsigned int, std::string, std::string>(user_id, time_string, msg))
-{
-}
-
-ServerReceiveChatMessage::ServerReceiveChatMessage(const std::string& msg) :
- Command(header::ServerReceiveChatMessage, msg)
-{
-
-}
-
ServerStartEncryptedSession::ServerStartEncryptedSession() :
Command(header::ServerStartEncryptedSession, "")
{
{
}
-ServerRequestedChatLog::ServerRequestedChatLog() :
- Command(header::ServerRequestedChatLog, "")
-{
-
-}
-
-ClientJoinPlayer::ClientJoinPlayer() :
- Command(header::ClientJoinPlayer, "")
-{
-
-}
-
-ClientLeavePlayer::ClientLeavePlayer() :
- Command(header::ClientLeavePlayer, "")
-{
-
-}
-
ClientUpdatePlayerPosition::ClientUpdatePlayerPosition
(unsigned int id, float x, float y, float z, float theta) :
Command(header::ClientUpdatePlayerPosition, Utils::Serialize(id, x, y, z, theta))
}
-ClientUpdateChannelUserList::ClientUpdateChannelUserList() :
- Command(header::ClientUpdateChannelUserList, "")
-{
-
-}
-
-ServerCloseSession::ServerCloseSession() :
- Command(header::ServerCloseSession, "")
-{
-
-}
-
-ServerReceiveNewCard::ServerReceiveNewCard(const std::string& name,
- const std::string& note,
- const std::string& url) :
- Command(header::ServerReceiveNewCard, Utils::Serialize(name, note, url))
-{
-}
-
-ServerRequestedCardRevisionPatch::ServerRequestedCardRevisionPatch(int revision) :
- Command(header::ServerRequestedCardRevisionPatch, Utils::Serialize(revision))
-{
-}
-
ServerRequestedAccountRevisionPatch::ServerRequestedAccountRevisionPatch(unsigned int user_id, int revision) :
Command(header::ServerRequestedAccountRevisionPatch,
Utils::Serialize(user_id, revision))
{
}
-
-ClientReceiveCardRevisionPatch::ClientReceiveCardRevisionPatch(const std::string& patch) :
- Command(header::ClientReceiveCardRevisionPatch, patch)
-{
-
-}
-
-ClientReceiveCardRevisionUpdateNotify::ClientReceiveCardRevisionUpdateNotify(int revision) :
- Command(header::ClientReceiveCardRevisionUpdateNotify, Utils::Serialize(revision))
-{
-}
-
ClientReceiveAccountRevisionPatch::ClientReceiveAccountRevisionPatch(const std::string& patch) :
Command(header::ClientReceiveAccountRevisionPatch, patch)
{
}
-PlayerLogoutNotify::PlayerLogoutNotify(unsigned int user_id) :
- Command(header::PlayerLogoutNotify, Utils::Serialize(user_id))
-{
-}
-
-ServerUpdatePlayerName::ServerUpdatePlayerName(const std::string& name) :
- Command(header::ServerUpdatePlayerName, name)
-{
-}
-
-ServerUpdatePlayerTrip::ServerUpdatePlayerTrip(const std::string& trip) :
- Command(header::ServerUpdatePlayerTrip, trip)
+ClientReceiveUnsupportVersionError::ClientReceiveUnsupportVersionError(uint32_t require_version) :
+ Command(header::ClientReceiveUnsupportVersionError, Utils::Serialize(require_version))
{
}
-ServerUpdatePlayerModelName::ServerUpdatePlayerModelName(const std::string& name) :
- Command(header::ServerUpdatePlayerModelName, name)
+ServerReceiveAccountInitializeData::ServerReceiveAccountInitializeData(const std::string& data):
+ Command(header::ServerReceiveAccountInitializeData, data)
{
-}
-ClientReceiveUnsupportVersionError::ClientReceiveUnsupportVersionError(uint32_t require_version) :
- Command(header::ClientReceiveUnsupportVersionError, Utils::Serialize(require_version))
-{
}
-ServerReceiveAccountInitializeData::ServerReceiveAccountInitializeData(const std::string& data):
- Command(header::ServerReceiveAccountInitializeData, data)
+ServerUpdateAccountProperty::ServerUpdateAccountProperty(AccountProperty property, const std::string& value) :
+Command(header::ServerUpdateAccountProperty, Utils::Serialize(property, value))
{
}
{
}
-
}
#include <boost/weak_ptr.hpp>
#include <stdint.h>
#include "CommandHeader.hpp"
+#include "../database/AccountProperty.hpp"
namespace network {
SessionWeakPtr session_;
};
-
- // コネクションの確立に成功
- class ConnectionSucceeded : public Command {
- public:
- ConnectionSucceeded();
- };
-
- // コネクションの確立に失敗
- class ConnectionFailed : public Command {
- public:
- ConnectionFailed();
- };
-
// コネクションの切断
class FatalConnectionError : public Command {
public:
FatalConnectionError(unsigned int user_id);
};
- // チャットメッセージを受信した
- class ClientReceiveChatMessage : public Command {
- public:
- ClientReceiveChatMessage(unsigned int user_id, const std::string& time_string, const std::string& msg);
- };
-
- // チャットメッセージを受信した
- class ServerReceiveChatMessage : public Command {
- public:
- ServerReceiveChatMessage(const std::string& msg);
- };
-
// 暗号化通信を開始
class ServerStartEncryptedSession : public Command {
public:
unsigned int user_id);
};
- // チャットログを受信した
- class ClientReceiveChatLog : public Command {
- public:
- ClientReceiveChatLog();
- };
-
- // チャットログを要求された
- class ServerRequestedChatLog : public Command {
- public:
- ServerRequestedChatLog();
- };
-
- // ユーザーが入室した
- class ClientJoinPlayer : public Command {
- public:
- ClientJoinPlayer();
- };
-
- // ユーザーが退室した
- class ClientLeavePlayer : public Command {
- public:
- ClientLeavePlayer();
- };
-
// 他のプレイヤーの位置情報が更新された
class ClientUpdatePlayerPosition : public Command {
public:
ClientRequestedClientInfo();
};
- // チャンネルのプレイヤーリストが更新された
- class ClientUpdateChannelUserList : public Command {
- public:
- ClientUpdateChannelUserList();
- };
-
- // セッションを切断された
- class ServerCloseSession : public Command {
- public:
- ServerCloseSession();
- };
-
- // カードの登録要求
- class ServerReceiveNewCard : public Command {
- public:
- ServerReceiveNewCard(const std::string& name,
- const std::string& note,
- const std::string& url);
- };
-
- //
- class ServerRequestedCardRevisionPatch : public Command {
- public:
- ServerRequestedCardRevisionPatch(int revision);
- };
-
class ServerRequestedAccountRevisionPatch : public Command {
public:
ServerRequestedAccountRevisionPatch(unsigned int user_id, int revision);
};
- // カードデータベースの更新データ
- class ClientReceiveCardRevisionPatch : public Command {
- public:
- ClientReceiveCardRevisionPatch(const std::string& patch);
- };
-
- // カードデータベースの更新通知
- class ClientReceiveCardRevisionUpdateNotify : public Command {
- public:
- ClientReceiveCardRevisionUpdateNotify(int revision);
- };
-
// アカウントデータベースの更新データ
class ClientReceiveAccountRevisionPatch : public Command {
public:
ClientReceiveServerCrowdedError();
};
- class PlayerLogoutNotify : public Command {
- public:
- PlayerLogoutNotify(unsigned int user_id);
- };
-
- class ServerUpdatePlayerName : public Command {
- public:
- ServerUpdatePlayerName(const std::string& name);
- };
-
- class ServerUpdatePlayerTrip : public Command {
- public:
- ServerUpdatePlayerTrip(const std::string& trip);
- };
-
class ClientReceiveUnsupportVersionError : public Command {
public:
ClientReceiveUnsupportVersionError(uint32_t require_version);
ServerReceiveAccountInitializeData(const std::string& data);
};
- class ServerUpdatePlayerModelName : public Command {
+ class ServerUpdateAccountProperty : public Command {
public:
- ServerUpdatePlayerModelName(const std::string& name);
+ ServerUpdateAccountProperty(AccountProperty propery, const std::string& value);
};
class ServerReceiveJSON : public Command {
namespace network {
namespace header {
enum CommandHeader {
- ConnectionSucceeded = 0x90000001,
- ConnectionFailed = 0xD0000002,
FatalConnectionError = 0xD0000003,
- ClientReceiveChatMessage = 0x80000004,
- ServerReceiveChatMessage = 0x00000005,
ServerStartEncryptedSession = 0x00000006,
ClientStartEncryptedSession = 0x80000007,
ServerReceivePublicKey = 0x00000008,
ClientReceiveCommonKey = 0x80000009,
- ClientReceiveChatLog = 0x8000000A,
- ServerRequestedChatLog = 0x2000000B,
- ClientJoinPlayer = 0x8000000C,
- ClientLeavePlayer = 0x8000000D,
ClientUpdatePlayerPosition = 0x8000000E,
ServerUpdatePlayerPosition = 0x0000000F,
ServerReceiveClientInfo = 0x00000010,
ClientRequestedPublicKey = 0xA0000011,
ClientRequestedClientInfo = 0xA0000012,
- ClientUpdateChannelUserList = 0x80000013,
- ServerCloseSession = 0x00000014,
- ServerReceiveNewCard = 0x00000015,
- ClientReceiveSystemMessage = 0x80000016,
- ServerRequestedRemoveCard = 0x20000017,
- ServerRequestedCardRevisionPatch = 0x20000018,
- ClientReceiveCardRevisionPatch = 0x80000019,
- ClientReceiveCardRevisionUpdateNotify = 0x8000001A,
ClientReceiveAccountRevisionPatch = 0x8000001B,
ServerRequestedAccountRevisionPatch = 0x2000001C,
ClientReceiveAccountRevisionUpdateNotify = 0x8000001D,
ClientReceiveWriteAverageLimitUpdate = 0x8000001E,
ClientReceiveServerCrowdedError = 0xC000001F,
- PlayerLogoutNotify = 0x10000020,
- ServerUpdatePlayerName = 0x00000021,
- ServerUpdatePlayerTrip = 0x00000022,
ClientReceiveUnsupportVersionError = 0xC0000023,
ServerReceiveAccountInitializeData = 0x00000024,
- ServerUpdatePlayerModelName = 0x00000025,
ClientReceiveServerInfo = 0x80000026,
+ ServerUpdateAccountProperty = 0x00000027,
ServerReceiveJSON = 0x00000040,
ClientReceiveJSON = 0x80000080
#include <stdexcept>
#include <cctype>
#include <boost/asio/ip/address.hpp>
+#include <boost/foreach.hpp>
namespace network {
namespace Utils {
{
std::string out;
- for (auto it = in.begin(); it != in.end(); ++it) {
- const char& c = *it;
+ BOOST_FOREACH(const char& c, in) {
if (c == 0x7e || c == 0x7d) {
out += 0x7d;
out += c ^ 0x20;
bool escape = false;
- for (auto it = in.begin(); it != in.end(); ++it) {
- const char& c = *it;
+ BOOST_FOREACH(const char& c, in) {
if (escape) {
out += c ^ 0x20;
escape = false;
{
std::string out;
- for (auto it = in.begin(); it != in.end(); ++it) {
- const char& c = *it;
+ BOOST_FOREACH(const char& c, in) {
out += (boost::format("%X ") % (int)c).str();
}
int bits_collected = 0;
unsigned int accumulator = 0;
- for (string::const_iterator i = ascdata.begin(); i != last; ++i) {
- const int c = *i;
+ BOOST_FOREACH(const int c, ascdata) {
if (::std::isspace(c) || c == '=') {
// Skip whitespace and padding. Be liberal in what you accept.
continue;
#ifdef _WIN32
- std::string sjis2utf8(std::string in) {
+ std::string sjis2utf8(const std::string& in) {
int wchar_size = ::MultiByteToWideChar(CP_ACP,0,in.data(),in.size(),nullptr,0);
auto wchar_buf = new wchar_t [wchar_size];
return out;
}
- std::string utf82sjis(std::string in) {
+ std::string utf82sjis(const std::string& in) {
int wchar_size = ::MultiByteToWideChar(CP_UTF8,0,in.data(),in.size(),nullptr,0);
auto wchar_buf = new wchar_t[wchar_size];
#ifdef _WIN32
-std::string sjis2utf8(std::string);
-std::string utf82sjis(std::string);
+std::string sjis2utf8(const std::string&);
+std::string utf82sjis(const std::string&);
std::string ToString(const std::wstring& s);
std::wstring ToWString(const std::string& s);
void Account::SetUserName(UserID user_id, const std::string& name)
{
- Set(user_id, NAME, name);
+ if (name.size() > 0 && name.size() <= 32) {
+ Set(user_id, NAME, name);
+ }
}
std::string Account::GetUserTrip(UserID user_id) const
void Account::SetUserTrip(UserID user_id, const std::string& trip)
{
- std::string crypted_trip = network::Encrypter::GetTrip(trip);
- Set(user_id, TRIP, crypted_trip);
+ if (trip.size() > 0 && trip.size() <= 64) {
+ std::string crypted_trip = network::Encrypter::GetTrip(trip);
+ Set(user_id, TRIP, crypted_trip);
+ }
}
std::string Account::GetUserModelName(UserID user_id) const
void Account::SetUserModelName(UserID user_id, const std::string& name)
{
- Set(user_id, MODEL_NAME, name);
+ if (name.size() > 0 && name.size() <= 64) {
+ Set(user_id, MODEL_NAME, name);
+ }
}
std::string Account::GetUserIPAddress(UserID user_id) const
// 通信量制限を越えていた場合、強制的に切断
else if (auto session = c.session().lock()) {
if (session->GetReadByteAverage() > session_read_average_) {
- if (auto session = c.session().lock()) {
- if (callback) {
- (*callback)(network::PlayerLogoutNotify(session->id()));
- }
- return;
- }
session->Close();
}
}
void Server::SendAll(const Command& command)
{
- for (auto it = sessions_.begin(); it != sessions_.end(); ++it) {
- SessionWeakPtr& ptr = *it;
+ BOOST_FOREACH(SessionWeakPtr& ptr, sessions_) {
if (auto session = ptr.lock()) {
session->Send(command);
}
void Server::SendOthers(const Command& command, SessionWeakPtr self_ptr)
{
- for (auto it = sessions_.begin(); it != sessions_.end(); ++it) {
- SessionWeakPtr& ptr = *it;
+ BOOST_FOREACH(SessionWeakPtr& ptr, sessions_) {
if (auto session = ptr.lock()) {
if (auto self = self_ptr.lock()) {
if (*session != *self) {
#include "Server.hpp"
#include "../common/network/Encrypter.hpp"
#include "../common/network/Signature.hpp"
+#include "../common/database/AccountProperty.hpp"
#include "../common/Logger.hpp"
#include "Config.hpp"
#include "Account.hpp"
}
break;
- // ユーザー名の更新
- case network::header::ServerUpdatePlayerName:
+ case network::header::ServerUpdateAccountProperty:
{
if (auto session = c.session().lock()) {
- std::string name = c.body();
- if (name.size() > 0 && name.size() <= 64) {
- account.SetUserName(session->id(), name);
- server.SendAll(
- network::ClientReceiveAccountRevisionUpdateNotify(session->id(),
- account.GetUserRevision(session->id())));
+ AccountProperty property;
+ std::string value;
+ network::Utils::Deserialize(c.body(), &property, &value);
+
+ auto old_revision = account.GetUserRevision(session->id());
+
+ switch (property) {
+
+ case NAME:
+ {
+ account.SetUserName(session->id(), value);
+ }
+ break;
+ case TRIP:
+ {
+ account.SetUserTrip(session->id(), value);
+ }
+ break;
+ case MODEL_NAME:
+ {
+ account.SetUserModelName(session->id(), value);
+ }
+ break;
+ default:
+ ;
}
- Logger::Info(msg);
- }
- }
- break;
- // トリップの更新
- case network::header::ServerUpdatePlayerTrip:
- {
- if (auto session = c.session().lock()) {
- std::string trip = c.body();
- if (trip.size() > 0 && trip.size() <= 64) {
- account.SetUserTrip(session->id(), trip);
+ auto new_revison = account.GetUserRevision(session->id());
+ if (new_revison > old_revision) {
server.SendAll(
- network::ClientReceiveAccountRevisionUpdateNotify(session->id(),
- account.GetUserRevision(session->id())));
+ network::ClientReceiveAccountRevisionUpdateNotify(
+ session->id(),new_revison));
}
+
Logger::Info(msg);
}
}
break;
- // ã\83¢ã\83\87ã\83«å\90\8dã\81®æ\9b´æ\96°
- case network::header::ServerUpdatePlayerModelName:
+ // ã\82¨ã\83©ã\83¼
+ case network::header::FatalConnectionError:
{
- if (auto session = c.session().lock()) {
- std::string name = c.body();
- if (name.size() > 0 && name.size() <= 64) {
- account.SetUserModelName(session->id(), name);
- server.SendAll(
- network::ClientReceiveAccountRevisionUpdateNotify(session->id(),
- account.GetUserRevision(session->id())));
- }
- Logger::Info(msg);
+ if (c.body().size() > 0) {
+ int user_id;
+ network::Utils::Deserialize(c.body(), &user_id);
+ account.LogOut(user_id);
+
+ server.SendAll(
+ network::ClientReceiveAccountRevisionUpdateNotify(user_id,
+ account.GetUserRevision(user_id)));
+
+ Logger::Info("Logout User: %d", user_id);
}
}
+ Logger::Info(msg);
break;
- // ログアウト
- case network::header::PlayerLogoutNotify:
- {
- Logger::Info(msg);
- }
- break;
-
- // エラー
- case network::header::FatalConnectionError:
- {
- if (c.body().size() > 0) {
- int user_id;
- network::Utils::Deserialize(c.body(), &user_id);
- account.LogOut(user_id);
-
- server.SendAll(
- network::ClientReceiveAccountRevisionUpdateNotify(user_id,
- account.GetUserRevision(user_id)));
-
- Logger::Info("Logout User: %d", user_id);
- }
- }
- Logger::Info(msg);
- break;
-
default:
break;
}