Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-05 10:17:39 +0000
committerStijn Buys <ingar@osirion.org>2008-07-05 10:17:39 +0000
commite5aada2bf01e51753829215c0a3035aa8bd8135a (patch)
tree65d7f5145334db1be780f177b93feb054f35cc82
parent68e4bbe3153f45139031a614541b2ccd80dd5526 (diff)
ncurses updates, refactored say
-rw-r--r--TODO11
-rw-r--r--osirion.kdevelop.pcsbin764410 -> 765753 bytes
-rw-r--r--osirion.kdevses34
-rw-r--r--src/client/console.cc2
-rw-r--r--src/core/application.cc15
-rw-r--r--src/core/commandbuffer.cc4
-rw-r--r--src/core/func.cc6
-rw-r--r--src/core/func.h2
-rw-r--r--src/core/gameconnection.cc12
-rw-r--r--src/core/gameconnection.h3
-rw-r--r--src/core/gameserver.cc11
-rw-r--r--src/core/gameserver.h2
-rw-r--r--src/server/console.cc91
-rw-r--r--src/server/console.h7
14 files changed, 157 insertions, 43 deletions
diff --git a/TODO b/TODO
index 6059c24..ae2df13 100644
--- a/TODO
+++ b/TODO
@@ -33,8 +33,9 @@ core:
parse command line options (ok)
execute command line options (ok)
globe entity (ok)
- zones
+ refactor 'say', it should not be a game function (ok)
+ zones
execute config files (ok, autoexec.cfg still missing)
game module loading/unloading
@@ -55,10 +56,11 @@ network:
client:
input handler switching (ok)
console chars (ok)
+ key bindings (ok)
keyboard handler, must be able to handle keyboard layouts
decent input handling implementation
- key bindings
+
on-the-fly cl_mousecontrol (toggle function)
render:
@@ -79,7 +81,6 @@ win32 port:
network not functional (ok)
texture loading is broken (ok)
screenshots are broken (ok)
-
- sound is broken
- directory creation
+ sound is broken (ok)
+ directory creation
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs
index 7d39b5d..2dbc80c 100644
--- a/osirion.kdevelop.pcs
+++ b/osirion.kdevelop.pcs
Binary files differ
diff --git a/osirion.kdevses b/osirion.kdevses
index 975ddcf..a84fe9f 100644
--- a/osirion.kdevses
+++ b/osirion.kdevses
@@ -1,13 +1,37 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE KDevPrjSession>
<KDevPrjSession>
- <DocsAndViews NumberOfDocuments="2" >
- <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/server/console.cc" >
- <View0 Encoding="" line="135" Type="Source" />
+ <DocsAndViews NumberOfDocuments="10" >
+ <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/server/server.cc" >
+ <View0 Encoding="" line="0" Type="Source" />
</Doc0>
- <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/netserver.cc" >
- <View0 Encoding="" line="214" Type="Source" />
+ <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/server/console.cc" >
+ <View0 Encoding="" line="23" Type="Source" />
</Doc1>
+ <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/commandbuffer.cc" >
+ <View0 Encoding="" line="157" Type="Source" />
+ </Doc2>
+ <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/console.cc" >
+ <View0 Encoding="" line="17" Type="Source" />
+ </Doc3>
+ <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/console.h" >
+ <View0 Encoding="" line="14" Type="Source" />
+ </Doc4>
+ <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/sys/consoleinterface.cc" >
+ <View0 Encoding="" line="0" Type="Source" />
+ </Doc5>
+ <Doc6 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/func.h" >
+ <View0 Encoding="" line="76" Type="Source" />
+ </Doc6>
+ <Doc7 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/func.cc" >
+ <View0 Encoding="" line="92" Type="Source" />
+ </Doc7>
+ <Doc8 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/gameserver.cc" >
+ <View0 Encoding="" line="72" Type="Source" />
+ </Doc8>
+ <Doc9 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/chat.cc" >
+ <View0 Encoding="" line="130" Type="Source" />
+ </Doc9>
</DocsAndViews>
<pluginList>
<kdevdebugger>
diff --git a/src/client/console.cc b/src/client/console.cc
index 6d286a9..b52f8a0 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -165,7 +165,7 @@ void Console::keypressed(unsigned int key)
else console_scroll = 0;
break;
default:
- if ((key >= 32 ) && (key <175)) {
+ if ((key >= 32 ) && (key <175) && ((*history_pos).size() < MAXCMDSIZE)) {
if (input_pos == (*history_pos).size())
(*history_pos) += (char)key;
else
diff --git a/src/core/application.cc b/src/core/application.cc
index cd6d278..f8c563c 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -59,6 +59,17 @@ void func_disconnect(std::string const &args)
application()->disconnect();
}
+void func_say(std::string const &args)
+{
+ if (connection()) {
+ connection()->say(args);
+ } else if (server()) {
+ server()->say(localplayer(), args);
+ } else {
+ con_print << "Not connected." << std::endl;
+ }
+}
+
// --------------- signal_handler -----------------------------------
#ifndef _WIN32
@@ -207,6 +218,9 @@ void Application::init(int count, char **arguments)
func = Func::add("disconnect", func_disconnect);
func->set_info("leave the current game");
+
+ func = Func::add("say",func_say);
+ func->set_info("say [text] say something on the public chat");
}
void Application::shutdown()
@@ -224,6 +238,7 @@ void Application::shutdown()
save_config();
// remove our engine functions
+ Func::remove("say");
Func::remove("help");
Func::remove("quit");
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index b34b04b..80e7e36 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -153,7 +153,9 @@ void CommandBuffer::exec(std::string const &cmdline)
while (cmdstream.get(c))
args += c;
}
- if ((f->flags() & Func::Game)) {
+
+ // console can not execute game functions, and neither should rcon
+ if ((f->flags() & Func::Game) && (Cvar::sv_dedicated->value() == 0)) {
if (application()->connected()) {
f->exec(game()->localplayer(), args);
}
diff --git a/src/core/func.cc b/src/core/func.cc
index 27c46a0..ad25426 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -81,7 +81,7 @@ Func *Func::find(const std::string &name)
void Func::list()
{
std::map<std::string, Func*>::iterator it;
- con_print << "Flags: G=Game" << std::endl;
+ con_print << "Flags: G=Game S=Shared" << std::endl;
for (it = registry.begin(); it != registry.end(); it++) {
std::string typeindicator;
@@ -89,6 +89,10 @@ void Func::list()
typeindicator += 'G';
else
typeindicator += ' ';
+ if (((*it).second->flags() & Shared) == Shared)
+ typeindicator += 'S';
+ else
+ typeindicator += ' ';
con_print << " " << typeindicator << " " << (*it).second->name() << " " << (*it).second->info() << std::endl;
}
diff --git a/src/core/func.h b/src/core/func.h
index 2c02599..d72e583 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -27,7 +27,7 @@ class Func
{
public:
/// function flags
- enum Flags {Game=1};
+ enum Flags {Game=1, Shared=2};
/// create a new function
Func(char const * name, void *ptr, unsigned int flags = 0);
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index 6090a52..4d2a745 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -68,7 +68,6 @@ void GameConnection::abort()
void GameConnection::forward(std::string const &cmdline)
{
-
if (!connection_network->connected())
return;
@@ -78,6 +77,17 @@ void GameConnection::forward(std::string const &cmdline)
connection_network->send(netmessage);
}
+void GameConnection::say(std::string const &args)
+{
+ if (!connection_network->connected())
+ return;
+
+ std::string netmessage("say ");
+ netmessage.append(args);
+ netmessage += '\n';
+ connection_network->send(netmessage);
+}
+
void GameConnection::frame(float seconds)
{
if (!running())
diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h
index 65fd495..d0da18e 100644
--- a/src/core/gameconnection.h
+++ b/src/core/gameconnection.h
@@ -36,6 +36,9 @@ public:
/// forward a command line to the remote server
void forward(std::string const &cmdline);
+ /// localplayer sends a chat message to the public channel
+ void say(std::string const &args);
+
/*----- static ---------------------------------------------------- */
/// return the current game connection
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index cddddff..c7a71ff 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -17,11 +17,6 @@
namespace core
{
-void func_say(Player *player, std::string const &args)
-{
- server()->say(player, args);
-}
-
void func_who(Player *player, std::string const &args)
{
server()->list_players(player);
@@ -74,9 +69,8 @@ GameServer::GameServer() : GameInterface()
server_network = 0;
}
- Func::add("say",func_say);
- Func::add("time", func_time);
- Func::add("who", func_who);
+ Func::add("time", func_time, Func::Shared);
+ Func::add("who", func_who, Func::Shared);
if (!Cvar::sv_dedicated->value()) {
player_connect(localplayer());
@@ -106,7 +100,6 @@ GameServer::~GameServer()
delete server_module;
}
- Func::remove("say");
Func::remove("time");
Func::remove("who");
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index a7ee159..3f8a2ec 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -46,7 +46,7 @@ public:
/// a player requests a list of who is connected
void list_players(Player *player);
- /// a player sends a chat message on the public channel
+ /// a player sends a chat message to the public channel
void say(Player *player, std::string const &args);
/// a player requests the current time
diff --git a/src/server/console.cc b/src/server/console.cc
index 6b24c0c..cdaa1f9 100644
--- a/src/server/console.cc
+++ b/src/server/console.cc
@@ -21,6 +21,8 @@ namespace server {
bool console_initialized = false;
bool console_updated = false;
+const size_t MAXHISTOLINES = 512;
+
Console server_console;
#ifdef HAVE_CURSES
@@ -63,7 +65,11 @@ void Console::init()
con_print << "Initializing console..." << std::endl;
#ifdef HAVE_CURSES
- server_console.console_lastrefresh = 1;
+ server_console.history.clear();
+ server_console.history.push_back("");
+ server_console.history_pos = server_console.history.rbegin();
+ server_console.input_pos = 0;
+
server_console.draw();
#endif // HAVE_CURSES
}
@@ -87,14 +93,8 @@ void Console::resize()
endwin();
refresh();
-
- draw_background();
- draw_text();
- draw_input();
- wrefresh(stdwin);
- console_updated = false;
- console_lastrefresh = 0;
+ draw();
}
void Console::flush()
@@ -199,7 +199,7 @@ void Console::draw_text()
int bottom = (int) consoleinterface_text.size() - console_scroll;
int current_line = 0;
- // parse cons0ole text, wrap long lines
+ // parse console text, wrap long lines
for (std::deque<std::string>::iterator it = consoleinterface_text.begin(); it != consoleinterface_text.end() && current_line < bottom; it++) {
if (current_line >= bottom - height) {
std::string linedata(*it);
@@ -312,18 +312,21 @@ void Console::draw_text()
void Console::draw_input()
{
- wmove(stdwin, stdwin->_maxy, 0);
+ color_set(0, NULL);
+ attron(A_BOLD);
+ // draw input text
+ mvaddstr(stdwin->_maxy, 0, ">");
+ mvaddstr(stdwin->_maxy, 1, (*history_pos).c_str());
+ // fill the remainder with spaces
+ for (int i=1 + (*history_pos).size(); i < stdwin->_maxx; i++)
+ addch(' ');
+ // move the cursor to input position
+ move(stdwin->_maxy, 1 + (*history_pos).size());
}
void Console::draw()
{
- flush();
-
- if (console_lastrefresh < 0.1) {
- return;
- }
-
- if (!(console_initialized && console_updated && stdwin->_maxx && stdwin->_maxy))
+ if (!console_initialized)
return;
draw_background();
@@ -337,17 +340,69 @@ void Console::draw()
void Console::frame(float seconds)
{
+ flush();
+
if (!console_initialized)
return;
console_lastrefresh += seconds;
+ bool input_updated = false;
int key = wgetch(stdwin);
while (key != ERR) {
+ if (key == KEY_BACKSPACE || key == 8 || key == 127) {
+ if ((*history_pos).size() && input_pos) {
+ (*history_pos).erase(input_pos-1, 1);
+ input_pos--;
+ input_updated = true;
+ }
+ break;
+ } else if (key == KEY_STAB || key ==9) {
+ core::CommandBuffer::complete( (*history_pos), input_pos);
+ input_updated = true;
+ break;
+ } else if (key == KEY_LEFT) {
+ } else if (key == KEY_HOME) {
+ } else if (key == KEY_RIGHT) {
+ } else if (key == KEY_END) {
+ } else if (key == KEY_UP) {
+ } else if (key == KEY_DOWN) {
+ } else if (key == KEY_ENTER || key == '\n') {
+ if ((*history_pos).size()) {
+ // store input into history
+ while (history.size() >= MAXHISTOLINES) {
+ history.pop_front();
+ }
+
+ core::cmd() << (*history_pos) << std::endl;
+ con_print << "^B>" << (*history_pos) << std::endl;
+ (*history.rbegin()) = (*history_pos);
+
+ history.push_back("");
+ history_pos = history.rbegin();
+ input_pos = 0;
+ input_updated = true;
+ }
+ break;
+ } else if (key == KEY_PPAGE) {
+ } else if (key == KEY_NPAGE) {
+ } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) {
+ if (input_pos == (*history_pos).size()) {
+ (*history_pos) += (char)key;
+ } else {
+ (*history_pos).insert(input_pos, 1, (char)key);
+ }
+ input_pos++;
+ input_updated = true;
+ }
key = wgetch(stdwin);
}
- draw();
+ if (console_updated) {
+ draw();
+ } else if (input_updated) {
+ draw_input();
+ }
}
#endif // HAVE_CURSES
diff --git a/src/server/console.h b/src/server/console.h
index eeee0ca..ed15c79 100644
--- a/src/server/console.h
+++ b/src/server/console.h
@@ -38,8 +38,15 @@ protected:
private:
/// set ncurses drawing color
void set_color(const char *color_code);
+ /// timestamp for screen refresh timeout
float console_lastrefresh;
+ // input history
+ std::deque<std::string> history;
+ std::deque<std::string>::reverse_iterator history_pos;
+
+ size_t input_pos;
+
#endif
};