summaryrefslogtreecommitdiffstats
path: root/src/client/user.cpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-11-25 00:18:43 +0300
committerJoursoir <chat@joursoir.net>2020-11-25 00:18:43 +0300
commit8dfca4755430209504dac5ed2e03a482342265b3 (patch)
tree393265d9d67a18b1bda32ea4f39d6dd4805cb35e /src/client/user.cpp
parentcd2decce51c32b8c0531a87ea849e9f8e80db0d3 (diff)
downloadwant-chat-8dfca4755430209504dac5ed2e03a482342265b3.tar.gz
want-chat-8dfca4755430209504dac5ed2e03a482342265b3.tar.bz2
want-chat-8dfca4755430209504dac5ed2e03a482342265b3.zip
client: remove menu, all actions move to chat, fix chat move
Diffstat (limited to 'src/client/user.cpp')
-rw-r--r--src/client/user.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/client/user.cpp b/src/client/user.cpp
index 85b626e..91b2450 100644
--- a/src/client/user.cpp
+++ b/src/client/user.cpp
@@ -10,6 +10,7 @@
#include "user.hpp"
+const int key_esc = 4;
const int key_enter = 10;
const int key_escape = 27;
const int key_backspace = 127;
@@ -57,7 +58,11 @@ void Client::Run(ChatRoom *room)
break;
}
else if(recive > 0) {
+ /* warning: if we get a message >= maxlen_outbuf then
+ this code will not work */
+ out_buffer[recive-1] = '\0'; // change '\n' to '\0'
room->AddMessage(out_buffer);
+ memset(out_buffer, 0, recive);
}
usleep(usecs);
@@ -69,6 +74,10 @@ void Client::HandleButton(ChatRoom *room)
int key = wgetch(room->GetInputWin());
switch(key)
{
+ case key_esc: {
+ // #todo: exit
+ break;
+ }
// ascii table 32...126
case ' '...'~': {
AddCharToBuffer(key);
@@ -92,7 +101,7 @@ void Client::HandleButton(ChatRoom *room)
void Client::AddCharToBuffer(char ch)
{
- if(in_buf_used >= max_line_length-2) // we reserve 1 byte for '\0'
+ if(in_buf_used >= maxlen_inbuf-1)
return;
in_buffer[in_buf_used] = ch;
@@ -114,9 +123,8 @@ void Client::SendMessage()
return;
in_buffer[in_buf_used] = '\n';
- // if(max_line_length-2 < 0)
write(fd, in_buffer, (in_buf_used+1)*sizeof(char));
- memset(in_buffer, 0, sizeof(in_buffer));
+ memset(in_buffer, 0, (in_buf_used+1)*sizeof(char));
in_buf_used = 0;
} \ No newline at end of file