forked from oerkki/voxelands
commands now work
This commit is contained in:
parent
02462fe854
commit
5d519799e6
|
@ -2,11 +2,34 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifndef SERVER
|
||||
#include "client.h"
|
||||
#endif
|
||||
#include "server.h"
|
||||
#include "environment.h"
|
||||
#include "player.h"
|
||||
#include "sha1.h"
|
||||
|
||||
#ifndef SERVER
|
||||
static Client *bridge_client = NULL;
|
||||
|
||||
void bridge_register_client(Client *c)
|
||||
{
|
||||
bridge_client = c;
|
||||
}
|
||||
|
||||
int bridge_client_send_msg(char* str)
|
||||
{
|
||||
if (!str)
|
||||
return 1;
|
||||
std::wstring m = narrow_to_wide(str);
|
||||
|
||||
bridge_client->sendChatMessage(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int bridge_server_get_status(command_context_t *ctx, char* buff, int size)
|
||||
{
|
||||
if (!ctx)
|
||||
|
|
|
@ -1237,7 +1237,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
}
|
||||
|
||||
/* because I can't remember which random stream prints to stdout */
|
||||
printf("CHAT: %s\n",wide_to_narrow(message).c_str());
|
||||
vlprint(CN_CHAT,(char*)wide_to_narrow(message).c_str());
|
||||
|
||||
m_chat_queue.push_back(message);
|
||||
}
|
||||
|
|
|
@ -134,10 +134,33 @@ static int command_set_detect(char* name)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int command_send_str(char* name, char* args)
|
||||
{
|
||||
#ifndef SERVER
|
||||
char buff[1024];
|
||||
|
||||
if (snprintf(buff,1024,"/%s %s",name,args) >= 1024)
|
||||
return 1;
|
||||
|
||||
return bridge_client_send_msg(buff);
|
||||
#else
|
||||
command_print(NULL, 0, CN_WARN, "Server-side command not sent: '%s'",name);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int command_send(char* name, array_t *args)
|
||||
{
|
||||
command_print(NULL, 0, CN_WARN, "Server-side command not sent: '%s'",name);
|
||||
return 1;
|
||||
char* str;
|
||||
int r;
|
||||
|
||||
str = array_join(args," ", 0);
|
||||
if (!str)
|
||||
return 1;
|
||||
|
||||
r = command_send_str(name,str);
|
||||
free(str);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int command_set(command_context_t *ctx, array_t *args)
|
||||
|
@ -363,7 +386,8 @@ int command_apply(command_context_t *ctx, char* name, char* value)
|
|||
}
|
||||
|
||||
if (!s->client && !ctx) {
|
||||
command_send(name,args);
|
||||
mutex_unlock(command_data.mutex);
|
||||
command_send_str(name,value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,6 +173,8 @@ int command_setpassword(command_context_t *ctx, array_t *args);
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#include <string>
|
||||
class Client;
|
||||
void bridge_register_client(Client *c);
|
||||
std::string bridge_config_get(char* name);
|
||||
#endif
|
||||
|
||||
|
@ -182,6 +184,7 @@ std::string bridge_config_get(char* name);
|
|||
#else
|
||||
#define EXTERNC
|
||||
#endif
|
||||
EXTERNC int bridge_client_send_msg(char* str);
|
||||
EXTERNC int bridge_server_get_status(command_context_t *ctx, char* buff, int size);
|
||||
EXTERNC int bridge_server_notify_player(command_context_t *ctx, char* name, char* str, ...);
|
||||
EXTERNC int bridge_server_settime(command_context_t *ctx, uint32_t time);
|
||||
|
|
23
src/game.cpp
23
src/game.cpp
|
@ -124,10 +124,15 @@ public:
|
|||
if (fields["text"] == L"")
|
||||
return;
|
||||
|
||||
// Send to others
|
||||
m_client->sendChatMessage(fields["text"]);
|
||||
// Show locally
|
||||
m_client->addChatMessage(fields["text"]);
|
||||
if (fields["text"][0] == L'/') {
|
||||
std::string m = wide_to_narrow(fields["text"]);
|
||||
command_exec(NULL,(char*)m.c_str());
|
||||
}else{
|
||||
// Send to others
|
||||
m_client->sendChatMessage(fields["text"]);
|
||||
// Show locally
|
||||
m_client->addChatMessage(fields["text"]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getForm()
|
||||
|
@ -686,6 +691,8 @@ void the_game(
|
|||
MapDrawControl draw_control;
|
||||
Client client(device, password, draw_control, sound);
|
||||
|
||||
bridge_register_client(&client);
|
||||
|
||||
drawLoadingScreen(device,narrow_to_wide(gettext("Resolving address...")));
|
||||
uint16_t port = config_get_int("world.server.port");
|
||||
if (!port)
|
||||
|
@ -703,6 +710,7 @@ void the_game(
|
|||
{
|
||||
errorstream<<"Couldn't resolve address"<<std::endl;
|
||||
error_message = narrow_to_wide(gettext("Couldn't resolve address"));
|
||||
bridge_register_client(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -781,6 +789,7 @@ void the_game(
|
|||
error_message = narrow_to_wide(gettext("Connection timed out."));
|
||||
errorstream<<"Timed out."<<std::endl;
|
||||
}
|
||||
bridge_register_client(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -788,8 +797,10 @@ void the_game(
|
|||
Create the camera node
|
||||
*/
|
||||
Camera camera(smgr, draw_control, &client);
|
||||
if (!camera.successfullyCreated(error_message))
|
||||
if (!camera.successfullyCreated(error_message)) {
|
||||
bridge_register_client(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
f32 camera_yaw = 0; // "right/left"
|
||||
f32 camera_pitch = 0; // "up/down"
|
||||
|
@ -2371,6 +2382,8 @@ void the_game(
|
|||
|
||||
clear_particles();
|
||||
|
||||
bridge_register_client(NULL);
|
||||
|
||||
/*
|
||||
Draw a "shutting down" screen, which will be shown while the map
|
||||
generator and other stuff quits
|
||||
|
|
|
@ -1190,7 +1190,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Save settings
|
||||
config_set("client.name", (char*)wide_to_narrow(menudata.name).c_str());
|
||||
config_set("world.admin.name",(char*)wide_to_narrow(menudata.name).c_str());
|
||||
config_set("world.server.admin",(char*)wide_to_narrow(menudata.name).c_str());
|
||||
|
||||
config_save(NULL,NULL,NULL);
|
||||
|
||||
|
@ -1281,6 +1281,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
} // Menu-game loop
|
||||
|
||||
config_save(NULL,NULL,NULL);
|
||||
|
||||
delete input;
|
||||
|
||||
if (sound != NULL)
|
||||
|
|
|
@ -4541,7 +4541,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
ctx.bridge_player = player;
|
||||
|
||||
if (command_exec(&ctx,(char*)message.c_str())) {
|
||||
line += L"Server: Invalid command";
|
||||
if (ctx.flags) {
|
||||
line += narrow_to_wide(ctx.reply);
|
||||
}else{
|
||||
line += L"Server: Invalid command";
|
||||
}
|
||||
send_to_sender = true;
|
||||
}else if (ctx.flags) {
|
||||
std::wstring reply(narrow_to_wide(ctx.reply));
|
||||
|
|
Loading…
Reference in New Issue