Commit 9ae35914 authored by Seblu's avatar Seblu
Browse files

envoie de commande

parent a27e0ea7
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -20,12 +20,10 @@ void Connection::start() {

  // send pass info


  return;
}

void Connection::stop() {
  return;
  disconnect_();
}

void Connection::connect_(const char *addr, int port) {
@@ -67,3 +65,21 @@ void Connection::disconnect_() {

  socket_ = 0;
}


void Connection::send(const string &data) {
  send(data.c_str(), data.length());
}

void Connection::send(const char* buf, size_t len) {
  write(socket_, buf, len);
}

void Connection::sendln(const string &data) {
  sendln(data.c_str(), data.length());
}

void Connection::sendln(const char* buf, size_t len) {
  write(socket_, buf, len);
  write(socket_, "\n", 1);
}
+2 −0
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ public:
  void stop();
  void send(const string &data);
  void send(const char* buf, size_t len);
  void sendln(const string &data);
  void sendln(const char* buf, size_t len);
  string recvln();
private:
  void connect_(const char *addr, int port);
+31 −2
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include "options.hh"
#include "error.hh"
#include "history.hh"
#include "connection.hh"

/*
*********************************************************************************
@@ -193,8 +194,8 @@ void Screen::eventsloop() {
      if (*cmd_buffer_ == 0) break;
      // save in history
      H.add(cmd_buffer_);
      // print to msg
      msg_println(cmd_buffer_);
      // Send to execution
      cmd_exec(cmd_buffer_);
      // purge buffer
      *cmd_buffer_ = 0;
      cmd_buf_off_ = 0;
@@ -498,6 +499,34 @@ void Screen::msg_save(const string &filename) const {

}

/*!
** Exec command or send if @param s is not a command.
*/
void Screen::cmd_exec(const char *s) {
  // string is a local command
  if (*s == '/') {
    if (!strcmp(s, "/exit")) {
      S << s << "\n";
      exit(0);
    }
    else if (!strcmp(s, "/logout")) {
      C.stop();
      S << s << "\n";
    }
    else if (!strcmp(s, "/login")) {
      C.start();
      S << s << "\n";
    }
    else
      S << s << ": Unkown command.\n";
  }
  // String is a remote command
  else {
    C.sendln(s, strlen(s));
    msg_println(s);
  }
}

/*!
** This is a sugar to print msg on msg window
**
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ private:
  void create_windows();

  void cmd_draw();
  void cmd_exec(const char *s);

  void msg_draw();
  void msg_add(const string &s);