Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
ServerScriptSequencer.h
Go to the documentation of this file.
1
2// =============================================================================
3// This file is adopted from rorserver at commit 4a7109ae2d9a081ccfdad8cc696dc54efe49acb3
4// Changes from the original are marked with "//RIGSOFRODS"
5// =============================================================================
6
7/*
8This file is part of "Rigs of Rods Server" (Relay mode)
9
10Copyright 2007 Pierre-Michel Ricordel
11Copyright 2014+ Rigs of Rods Community
12
13"Rigs of Rods Server" is free software: you can redistribute it
14and/or modify it under the terms of the GNU General Public License
15as published by the Free Software Foundation, either version 3
16of the License, or (at your option) any later version.
17
18"Rigs of Rods Server" is distributed in the hope that it will
19be useful, but WITHOUT ANY WARRANTY; without even the implied
20warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with Foobar. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#pragma once
28
29#ifdef USE_ANGELSCRIPT
30
31#include "ForwardDeclarations.h"
32
33#include <map>
34#include <mutex>
35#include <thread>
36#include <vector>
37#include "angelscript.h"
38#include "RoRnet.h"
39
40namespace RoR { // RIGSOFRODS
41
42// This is used to define who says it, when the server says something
49
51// order: least restrictive to most restrictive!
52 BROADCAST_AUTO = -1, // Do not edit the publishmode (for scripts only)
53 BROADCAST_ALL, // broadcast to all clients including sender
54 BROADCAST_NORMAL, // broadcast to all clients except sender
55 BROADCAST_AUTHED, // broadcast to authed users (bots)
56 BROADCAST_BLOCK // no broadcast
57};
58
59// constant for functions that receive an uid for sending something
60static const int TO_ALL = -1;
61
62struct ServerScriptClient { // RIGSOFRODS: Bare minimum from `class Client` in rorserver.
64 std::map<unsigned int, RoRnet::StreamRegister> streams;
65};
66
67class ServerScriptSequencer // RIGSOFRODS: Bare minimum from `class Sequencer` in rorserver.
68{
69 friend class ServerScript;
70public:
73
74 int Initialize(const std::string& script_filename); // Creates scripting engine and loads the server script. Returns 0 on success.
75 bool IsRunning() { return m_script_engine != nullptr; }
76 void Close();
77
78 // Synchronized public interface
79 void createClient(RoRnet::UserInfo& user); // Performs the 'playerAdded' callback.
80 int getNumClients();
81 void frameStepScripts(float dt);
82 int getStartTime();
83
84 // RIGSOFRODS: chops of `queueMessage()` in rorserver.
86 void queueMessageStreamUnregister(int uid, unsigned int streamid);
87 void queueMessageUserLeave(int uid);
88 void queueMessagePlayerChat(int uid, const std::string & data);
89 void queueMessageGameCmd(int uid, const std::string & data);
90
91private:
92 // Helpers (not thread safe - only call when clients-mutex is locked!)
93 ServerScriptClient* FindClientById(unsigned int client_id);
95 void QueueClientForDisconnect(int client_id); // RIGSOFRODS: We always call 'playerDeleted' callback externally - even rorserver does it mostly so.
96 void serverSay(std::string msg, int uid = -1, int type = 0);
97 void sendGameCommand(int uid, std::string cmd);
98 bool CheckNickIsUnique(std::string &nick);
100 bool Kick(int to_kick_uid);
101
102 std::unique_ptr<ServerScriptEngine> m_script_engine;
103
104 std::mutex m_clients_mutex;
105 std::vector<ServerScriptClient *> m_clients;
106 unsigned int m_free_user_id = 1;
108};
109
110} // namespace RoR
111
112#endif //USE_ANGELSCRIPT
Global forward declarations.
std::vector< ServerScriptClient * > m_clients
void sendGameCommand(int uid, std::string cmd)
void queueMessageGameCmd(int uid, const std::string &data)
ServerScriptClient * getClient(int uid)
std::mutex m_clients_mutex
guards access to m_clients and execution of script callbacks.
int Initialize(const std::string &script_filename)
bool CheckNickIsUnique(std::string &nick)
void serverSay(std::string msg, int uid=-1, int type=0)
void queueMessageStreamUnregister(int uid, unsigned int streamid)
void queueMessageStreamRegister(int uid, RoRnet::StreamRegister *reg)
ServerScriptClient * FindClientById(unsigned int client_id)
void queueMessagePlayerChat(int uid, const std::string &data)
void createClient(RoRnet::UserInfo &user)
void QueueClientForDisconnect(int client_id)
std::unique_ptr< ServerScriptEngine > m_script_engine
static const int TO_ALL
RoRnet::UserInfo user
user information
std::map< unsigned int, RoRnet::StreamRegister > streams
< Sent from the client to server and vice versa, to broadcast a new stream
Definition RoRnet.h:160