mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
load and save groups
This commit is contained in:
@@ -566,27 +566,6 @@ bool Network::Init()
|
||||
}
|
||||
#endif
|
||||
|
||||
// Hardcoded permission groups
|
||||
std::unique_ptr<NetworkGroup> admin(new NetworkGroup()); // change to make_unique in c++14
|
||||
admin->SetName("Admin");
|
||||
admin->actions_allowed.fill(0xFF);
|
||||
admin->id = 0;
|
||||
group_list.push_back(std::move(admin));
|
||||
std::unique_ptr<NetworkGroup> spectator(new NetworkGroup()); // change to make_unique in c++14
|
||||
spectator->SetName("Spectator");
|
||||
spectator->ToggleActionPermission(0); // Chat
|
||||
spectator->id = 1;
|
||||
group_list.push_back(std::move(spectator));
|
||||
std::unique_ptr<NetworkGroup> user(new NetworkGroup()); // change to make_unique in c++14
|
||||
user->SetName("User");
|
||||
user->actions_allowed.fill(0xFF);
|
||||
user->ToggleActionPermission(15); // Kick Player
|
||||
user->ToggleActionPermission(16); // Modify Groups
|
||||
user->ToggleActionPermission(17); // Set Player Group
|
||||
user->id = 2;
|
||||
group_list.push_back(std::move(user));
|
||||
SetDefaultGroup(1);
|
||||
|
||||
status = NETWORK_STATUS_READY;
|
||||
return true;
|
||||
}
|
||||
@@ -686,6 +665,8 @@ bool Network::BeginServer(unsigned short port, const char* address)
|
||||
return false;
|
||||
}
|
||||
|
||||
LoadGroups();
|
||||
|
||||
NetworkPlayer* player = AddPlayer();
|
||||
player->SetName(gConfigNetwork.player_name);
|
||||
player->flags |= NETWORK_PLAYER_FLAG_ISSERVER;
|
||||
@@ -1177,6 +1158,87 @@ void Network::SetDefaultGroup(uint8 id)
|
||||
}
|
||||
}
|
||||
|
||||
void Network::SaveGroups()
|
||||
{
|
||||
if (GetMode() == NETWORK_MODE_SERVER) {
|
||||
utf8 path[MAX_PATH];
|
||||
SDL_RWops *file;
|
||||
|
||||
platform_get_user_directory(path, NULL);
|
||||
strcat(path, "groups.cfg");
|
||||
|
||||
file = SDL_RWFromFile(path, "wb");
|
||||
if (file == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<NetworkPacket> stream = std::move(NetworkPacket::Allocate());
|
||||
*stream << (uint8)group_list.size();
|
||||
*stream << default_group;
|
||||
for (auto it = group_list.begin(); it != group_list.end(); it++) {
|
||||
(*it)->Write(*stream);
|
||||
}
|
||||
|
||||
SDL_RWwrite(file, stream->GetData(), stream->data->size(), 1);
|
||||
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::LoadGroups()
|
||||
{
|
||||
group_list.clear();
|
||||
|
||||
utf8 path[MAX_PATH];
|
||||
SDL_RWops *file;
|
||||
|
||||
platform_get_user_directory(path, NULL);
|
||||
strcat(path, "groups.cfg");
|
||||
|
||||
file = SDL_RWFromFile(path, "rb");
|
||||
if (file == NULL) {
|
||||
// Hardcoded permission groups
|
||||
std::unique_ptr<NetworkGroup> admin(new NetworkGroup()); // change to make_unique in c++14
|
||||
admin->SetName("Admin");
|
||||
admin->actions_allowed.fill(0xFF);
|
||||
admin->id = 0;
|
||||
group_list.push_back(std::move(admin));
|
||||
std::unique_ptr<NetworkGroup> spectator(new NetworkGroup()); // change to make_unique in c++14
|
||||
spectator->SetName("Spectator");
|
||||
spectator->ToggleActionPermission(0); // Chat
|
||||
spectator->id = 1;
|
||||
group_list.push_back(std::move(spectator));
|
||||
std::unique_ptr<NetworkGroup> user(new NetworkGroup()); // change to make_unique in c++14
|
||||
user->SetName("User");
|
||||
user->actions_allowed.fill(0xFF);
|
||||
user->ToggleActionPermission(15); // Kick Player
|
||||
user->ToggleActionPermission(16); // Modify Groups
|
||||
user->ToggleActionPermission(17); // Set Player Group
|
||||
user->id = 2;
|
||||
group_list.push_back(std::move(user));
|
||||
SetDefaultGroup(1);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<NetworkPacket> stream = std::move(NetworkPacket::Allocate());
|
||||
uint8 byte;
|
||||
while(SDL_RWread(file, &byte, sizeof(byte), 1)){
|
||||
*stream << byte;
|
||||
}
|
||||
stream->size = (uint16)stream->data->size();
|
||||
|
||||
uint8 num;
|
||||
*stream >> num >> default_group;
|
||||
for (unsigned int i = 0; i < num; i++) {
|
||||
NetworkGroup group;
|
||||
group.Read(*stream);
|
||||
std::unique_ptr<NetworkGroup> newgroup(new NetworkGroup(group)); // change to make_unique in c++14
|
||||
group_list.push_back(std::move(newgroup));
|
||||
}
|
||||
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
void Network::Client_Send_AUTH(const char* name, const char* password)
|
||||
{
|
||||
std::unique_ptr<NetworkPacket> packet = std::move(NetworkPacket::Allocate());
|
||||
@@ -2157,6 +2219,8 @@ void game_command_modify_groups(int *eax, int *ebx, int *ecx, int *edx, int *esi
|
||||
}break;
|
||||
}
|
||||
|
||||
gNetwork.SaveGroups();
|
||||
|
||||
*ebx = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,6 +304,8 @@ public:
|
||||
void RemoveGroup(uint8 id);
|
||||
uint8 GetDefaultGroup();
|
||||
void SetDefaultGroup(uint8 id);
|
||||
void SaveGroups();
|
||||
void LoadGroups();
|
||||
|
||||
void Client_Send_AUTH(const char* name, const char* password);
|
||||
void Server_Send_AUTH(NetworkConnection& connection);
|
||||
|
||||
Reference in New Issue
Block a user