49 Ogre::ColourValue(0.0, 0.8, 0.0),
50 Ogre::ColourValue(0.0, 0.4, 0.701960784314),
51 Ogre::ColourValue(1.0, 0.501960784314, 0.0),
52 Ogre::ColourValue(1.0, 0.8, 0.0),
55 Ogre::ColourValue(0.8, 1.0, 0.0),
56 Ogre::ColourValue(1.0, 0.0, 0.0),
57 Ogre::ColourValue(0.501960784314, 0.501960784314, 0.501960784314),
58 Ogre::ColourValue(0.0, 0.560784313725, 0.0),
60 Ogre::ColourValue(0.701960784314, 0.352941176471, 0.0),
61 Ogre::ColourValue(0.701960784314, 0.560784313725, 0.0),
63 Ogre::ColourValue(0.560784313725, 0.701960784314, 0.0),
64 Ogre::ColourValue(0.701960784314, 0.0, 0.0),
65 Ogre::ColourValue(0.745098039216, 0.745098039216, 0.745098039216),
66 Ogre::ColourValue(0.501960784314, 1.0, 0.501960784314),
67 Ogre::ColourValue(0.501960784314, 0.788235294118, 1.0),
68 Ogre::ColourValue(1.0, 0.752941176471, 0.501960784314),
69 Ogre::ColourValue(1.0, 0.901960784314, 0.501960784314),
70 Ogre::ColourValue(0.666666666667, 0.501960784314, 1.0),
71 Ogre::ColourValue(0.933333333333, 0.0, 0.8),
72 Ogre::ColourValue(1.0, 0.501960784314, 0.501960784314),
73 Ogre::ColourValue(0.4, 0.4, 0.0),
74 Ogre::ColourValue(1.0, 0.749019607843, 1.0),
75 Ogre::ColourValue(0.0, 1.0, 0.8),
76 Ogre::ColourValue(0.8, 0.4, 0.6),
77 Ogre::ColourValue(0.6, 0.6, 0.0),
84#define LOG_THREAD(_MSG_) { std::stringstream s; s << _MSG_ << " (Thread ID: " << std::this_thread::get_id() << ")"; LOG(s.str()); }
85#define LOGSTREAM Ogre::LogManager().getSingleton().stream()
96 int numColours =
sizeof(
MP_COLORS) /
sizeof(Ogre::ColourValue);
97 if (color_num < 0 || color_num >= numColours)
98 return Ogre::ColourValue::White;
106 std::stringstream msg;
107 msg <<
"++ " << name <<
": " << header->
source <<
", " << header->
streamid
129 SWBaseSocket::SWBaseError error;
131 if (
m_socket.fsend(buffer, msgsize, &error) < msgsize)
133 LOG(
"NET send error: " + error.get_error());
175 SWBaseSocket::SWBaseError error;
178 LOG_THREAD(
"[RoR|Networking] ReceiveMessage() waiting...");
183 LOG(
"NET receive error 1: " + error.get_error());
188 LOG_THREAD(
"[RoR|Networking] ReceiveMessage() header received");
191 if (head->
size > uint32_t(bufferlen))
199 std::memset(content, 0, bufferlen);
200 if (
m_socket.frecv(content, head->
size, &error) <
static_cast<int>(head->
size))
202 LOG_THREAD(
"NET receive error 2: "+ error.get_error());
208 LOG_THREAD(
"[RoR|Networking] ReceiveMessage() body received");
216 LOG(
"[RoR|Networking] SendThread started");
235 LOG(
"[RoR|Networking] SendThread stopped");
240 LOG_THREAD(
"[RoR|Networking] RecvThread starting...");
252 LOG_THREAD(
"[RoR|Networking] RecvThread: Error while receiving data: " +
TOSTRING(err));
282 if (header.
size !=
sizeof(
int))
286 int quality = *(
int *)buffer;
296 std::stringstream msg;
297 msg <<
_L(
"disconnected: remote side closed the connection");
301 bool was_kick = (std::strstr(buffer,
"disconnected on request") ==
nullptr);
310 auto user = std::find_if(
m_users.begin(),
m_users.end(), [header](
const RoRnet::UserInfo& u) { return static_cast<int>(u.uniqueid) == header.source; });
315 text <<
_L(
"left the game");
321 int peeropt_offset = (int)std::distance(
m_users.begin(), user);
352 text <<
_L(
"joined the game");
368#ifdef USE_ANGELSCRIPT
378 LOG_THREAD(
"[RoR|Networking] RecvThread stopped");
410 catch (std::exception& e)
414 RoR::LogFormat(
"[RoR|Networking] Failed to launch connection thread, message: %s", e.what());
431 SWBaseSocket::SWBaseError error;
437 if (error != SWBaseSocket::ok)
456 CouldNotConnect(
_L(
"Establishing network session: error getting server version"));
463 std::string format_str =
_L(
"Establishing network session: wrong server version, you are using version '%s' and the server is using '%s'");
484 std::string formatstr =
_L(
"Establishing network session: wrong server version, you are using version '%s' and the server is using '%s'");
505 strncpy(c.
language, (language + std::string(
"_") + country).c_str(), 5);
516 CouldNotConnect(
_L(
"Establishing network session: error getting server authorization"));
522 CouldNotConnect(
_L(
"Establishing network session: sorry, server has too many players"));
528 CouldNotConnect(
_L(
"Establishing network session: sorry, you are banned!"),
false);
538 CouldNotConnect(
_L(
"Establishing network session: sorry, wrong protocol version!"));
543 CouldNotConnect(
_L(
"Establishing network session: sorry, this server requires a user token!"));
551 CouldNotConnect(
_L(
"Establishing network session: sorry, unknown server response"));
564 LOG(
"[RoR|Networking] Connect(): Creating Send/Recv threads");
574 LOG(
"[RoR|Networking] Disconnect() disconnecting...");
582 LOG(
"[RoR|Networking] Disconnect() sender thread cleaned up");
586 if (is_clean_disconnect)
592 LOG(
"[RoR|Networking] Disconnect() receiver thread cleaned up");
594 if (is_clean_disconnect)
613 LOG(
"[RoR|Networking] Disconnect() done");
621 LOGSTREAM <<
"[RoR|Networking] Discarding network packet (StreamID: "
622 <<streamid<<
", Type: "<<type<<
"), length is " << len <<
", max is " << max_len;
629 char *buffer = (
char*)(packet.
buffer);
639 memcpy(bufferContent, content, len);
654 [&](
const NetSendPacket& p) { return !memcmp(packet.buffer, p.buffer, sizeof(RoRnet::Header)); });
730 if ((
int)user.uniqueid == uid)
742 for (
size_t i = 0; i <
m_users.size(); i++)
744 if (
static_cast<int>(
m_users[i].uniqueid) == uid)
758 if ((
int)user.uniqueid == uid)
794 if (user.username == username)
810 if (!peeropts_sane)
return;
812 for (
size_t i = 0; i <
m_users.size(); i++)
827 if (!peeropts_sane)
return;
829 for (
size_t i = 0; i <
m_users.size(); i++)
847 size_t payload_len = 0;
851 payload_len +=
sizeof(user.
uniqueid);
854 std::strncpy(payload + payload_len, msg,
sizeof(payload) - payload_len);
855 payload_len += std::strlen(msg);
868 else {
return _LC(
"NetUserAuth",
"Guest"); }
878 else {
return _LC(
"NetUserAuth",
"Guest"); }
Central state/object manager and communications hub.
#define ROR_ASSERT(_EXPR)
void LOG(const char *msg)
Legacy alias - formerly a macro.
#define BITMASK_SET_0(VAR, FLAGS)
#define BITMASK_SET_1(VAR, FLAGS)
Game state manager and message-queue provider.
void DebugPacket(const char *name, RoRnet::Header *header, char *buffer)
static Ogre::ColourValue MP_COLORS[]
#define LOG_THREAD(_MSG_)
static const unsigned int m_packet_buffer_size
const char *const ROR_VERSION_STRING
std::string const & getStr() const
void putNetMessage(int user_id, MessageType type, const char *text)
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
void ChainMessage(Message m)
Add to last pushed message's chain.
bool GetUserPeerOpts(int uid, BitMask_t &result)
std::deque< NetSendPacket > m_send_packet_buffer
Ogre::ColourValue GetPlayerColor(int color_num)
bool FindUserInfo(std::string const &username, RoRnet::UserInfo &result)
void AddLocalStream(RoRnet::StreamRegister *reg, int size)
int ReceiveMessage(RoRnet::Header *head, char *content, int bufferlen)
std::string UserAuthToStringLong(RoRnet::UserInfo const &user)
std::string GetUsername()
std::thread m_connect_thread
void RemovePeerOptions(PeerOptionsRequest *rq)
void CouldNotConnect(std::string const &msg, bool close_socket=true)
bool GetAnyUserInfo(int uid, RoRnet::UserInfo &result)
Also considers local client.
bool SendMessageRaw(char *buffer, int msgsize)
std::vector< BitMask_t > GetAllUsersPeerOpts()
std::vector< RoRnet::UserInfo > m_disconnected_users
std::atomic< int > m_net_quality
void BroadcastChatMsg(const char *msg)
std::vector< NetRecvPacket > GetIncomingStreamData()
std::mutex m_send_packetqueue_mutex
bool GetDisconnectedUserInfo(int uid, RoRnet::UserInfo &result)
std::string UserAuthToStringShort(RoRnet::UserInfo const &user)
std::atomic< bool > m_shutdown
std::vector< NetRecvPacket > m_recv_packet_buffer
bool StartConnecting()
Launches connecting on background.
void SetNetQuality(int quality)
bool SendNetMessage(int type, unsigned int streamid, int len, char *content)
std::thread m_send_thread
void AddPacket(int streamid, int type, int len, const char *content)
RoRnet::ServerInfo m_server_settings
std::thread m_recv_thread
RoRnet::UserInfo GetLocalUserData()
std::mutex m_recv_packetqueue_mutex
void PushNetMessage(MsgType type, std::string const &message)
std::vector< BitMask_t > m_users_peeropts
See RoRnet::PeerOptions.
RoRnet::UserInfo m_userdata
std::mutex m_userdata_mutex
Ogre::String GetTerrainName()
void QueueStreamData(RoRnet::Header &header, char *buffer, size_t buffer_len)
void WhisperChatMsg(RoRnet::UserInfo const &user, const char *msg)
bool GetUserInfo(int uid, RoRnet::UserInfo &result)
std::vector< RoRnet::UserInfo > GetUserInfos()
std::vector< RoRnet::UserInfo > m_users
void AddPeerOptions(PeerOptionsRequest *rq)
std::condition_variable m_send_packet_available_cv
void queueStringForExecution(const Ogre::String command)
Queues a string for execution.
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
const char * ToCStr() const
void doCommand(std::string msg)
Identify and execute any console line.
@ DISABLED
Not connected for whatever reason.
MsgType
Global gameplay message loop, see struct Message in GameContext.h.
@ MSG_NET_CONNECT_STARTED
@ MSG_NET_CONNECT_FAILURE
@ MSG_GUI_MP_CLIENTS_REFRESH
@ MSG_NET_CONNECT_PROGRESS
@ MSG_NET_CONNECT_SUCCESS
@ MSG_NET_USER_DISCONNECT
@ MSG_GUI_OPEN_MP_SETTINGS_REQUESTED
CVar * mp_server_password
GameContext * GetGameContext()
ScriptEngine * GetScriptEngine()
Ogre::String HashData(const char *key, int len)
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.
std::string Sha1Hash(std::string const &data)
@ AUTH_MOD
moderator status
@ AUTH_RANKED
ranked status
@ AUTH_ADMIN
admin on the server
@ MSG2_STREAM_REGISTER_RESULT
result of a stream creation
@ MSG2_STREAM_DATA_DISCARDABLE
stream data that is allowed to be discarded
@ MSG2_NO_RANK
client has no ranked status
@ MSG2_WRONG_VER_LEGACY
Wrong version.
@ MSG2_WRONG_VER
wrong version
@ MSG2_USER_LEAVE
user leaves
@ MSG2_USER_INFO
user data that is sent from the server to the clients
@ MSG2_WELCOME
we can proceed
@ MSG2_STREAM_UNREGISTER
remove stream
@ MSG2_HELLO
client sends its version as first message
@ MSG2_USER_JOIN
new user joined
@ MSG2_UTF8_CHAT
broadcast chat line in UTF8 encoding; Payload: const char*(text)
@ MSG2_FULL
no more slots for us
@ MSG2_GAME_CMD
Script message. Can be sent in both directions.
@ MSG2_NETQUALITY
network quality information
@ MSG2_UTF8_PRIVCHAT
private chat line in UTF8 encoding; Payload: uint32_t(uniqueid), const char*(text)
@ MSG2_WRONG_PW
server send that on wrong pw
@ MSG2_STREAM_REGISTER
create new stream
@ MSG2_BANNED
client not allowed to join
#define RORNET_MAX_MESSAGE_LENGTH
maximum size of a RoR message. 8192 bytes = 8 kibibytes
#define RORNET_MAX_USERNAME_LEN
bytes.
Unified game event system - all requests and state changes are reported using a message.
char buffer[RORNET_MAX_MESSAGE_LENGTH]
char buffer[RORNET_MAX_MESSAGE_LENGTH]
Payload of MSG_NET_{ADD/REMOVE}_PEEROPTIONS_REQUESTED.
int por_uid
RoRnet unique user ID.
BitMask_t por_peeropts
See RoRnet::PeerOptions.
char protocolversion[20]
protocol version being used
char terrain[128]
terrain name
char protocolversion[20]
protocol version being used
< Sent from the client to server and vice versa, to broadcast a new stream
int32_t type
0 = Actor, 1 = Character, 3 = ChatSystem
int32_t origin_streamid
origin streamid
int32_t origin_sourceid
origin sourceid
int32_t status
initial stream status
int32_t authstatus
auth status set by server: AUTH_*
char clientname[10]
the name and version of the client. For exmaple: "ror" or "gamebot"
char language[10]
user's language. For example "de-DE" or "en-US"
char username[RORNET_MAX_USERNAME_LEN]
the nickname of the user (UTF-8)
int32_t colournum
colour set by server
char usertoken[40]
user token
char serverpassword[40]
server password
char sessiontype[10]
the requested session type. For example "normal", "bot", "rcon"
uint32_t uniqueid
user unique id
char clientversion[25]
a version number of the client. For example 1 for RoR 0.35