Commit 9c1a2ddd authored by stettberger's avatar stettberger

Auto Away

parent a29f8eab
......@@ -30,6 +30,7 @@
#include <errno.h>
#include <getopt.h>
#include <dirent.h>
#include <time.h>
/* {{{ Structs, Globals Declarations */
#define VERSION "0.1 beta"
......@@ -41,6 +42,7 @@ typedef struct {
/* Config */
int sign:1;
int detach_on_signal:1;
int auto_away:1;
} *Silc;
typedef struct Channel Channel;
......@@ -70,6 +72,7 @@ int debug=1;
int connected=0;
SilcClientOperations ops;
Silc silc_client;
time_t last_input;
int LocalToUtf8 (char *from, char **to);
int Utf8ToLocal (char *from, char **to);
......@@ -317,6 +320,18 @@ void proc_channels_input(Channel *c, char *buf) {
else
print_out(c->silc->channel_name, "-!- Error: False Argument");
}
else if (!strncmp("auto_away ", &buf[5], 10)) {
if (!strncmp("on", &buf[15], 2)){
silc_client->auto_away=TRUE;
print_out(c->silc->channel_name, "-!- Auto away: on");
}
else if (!strncmp("off", &buf[15], 3)){
silc_client->auto_away=FALSE;
print_out(c->silc->channel_name, "-!- Auto away: off");
}
else
print_out(c->silc->channel_name, "-!- Error: False Argument");
}
else
print_out(c->silc->channel_name, "-!- Error: False Argument");
}
......@@ -328,12 +343,17 @@ void proc_channels_input(Channel *c, char *buf) {
else {
if(strlen(msg)!=0) {
DEBUG("Input: SENT");
if (strlen(c->silc->channel_name)!=0) {
silc_client_send_channel_message(silc_client->client,silc_client->conn,c->silc,
c->silc->curr_key,SILC_MESSAGE_FLAG_UTF8
|(silc_client->sign?SILC_MESSAGE_FLAG_SIGNED:0),
(unsigned char *)msg,len,TRUE);
DEBUG("Input: SENT");
last_input=time(NULL);
if(silc_client->conn->local_entry->mode & SILC_UMODE_GONE
|| silc_client->conn->local_entry->mode & SILC_UMODE_INDISPOSED)
silc_client_command_call(silc_client->client, silc_client->conn, "umode -gi", NULL);
silc_client_send_channel_message(silc_client->client,silc_client->conn,c->silc,
c->silc->curr_key,SILC_MESSAGE_FLAG_UTF8
|(silc_client->sign?SILC_MESSAGE_FLAG_SIGNED:0),
(unsigned char *)msg,len,TRUE);
/* Write it to the Channel */
SilcChannelUser cuser;
cuser=silc_client_on_channel(c->silc, silc_client->conn->local_entry);
......@@ -515,7 +535,7 @@ char *silc_client_umode(SilcUInt32 mode) {
return stat;
}
/* }}} */
/* {{{ silc_verify_payload */
/* {{{ silc_verify_message */
char *silc_verify_message(SilcClientEntry sender, SilcMessagePayload message) {
char *retval=malloc(5);
if(!retval){
......@@ -667,7 +687,20 @@ void run_once() {
int r, maxfd=0;
fd_set rd;
struct timeval tv;
if (silc_client->auto_away){
if ((time(NULL)-last_input)>=600){
if(!(silc_client->conn->local_entry->mode & SILC_UMODE_INDISPOSED)){
silc_client_command_call(silc_client->client, silc_client->conn, "umode +i", NULL);
last_input=time(NULL);
}
}
if ((time(NULL)-last_input)>=1200){
if(!(silc_client->conn->local_entry->mode & SILC_UMODE_GONE)){
silc_client_command_call(silc_client->client, silc_client->conn, "umode +g", NULL);
last_input=time(NULL);
}
}
}
FD_ZERO(&rd);
for(c = channels; c; c = c->next) {
if(maxfd < c->fd)
......@@ -730,6 +763,8 @@ int run(void)
/* Set Signed Messages per Default to off */
silc_client->sign=FALSE;
silc_client->auto_away=FALSE;
last_input=time(NULL);
/* Now we initialize the client. */
if (!silc_client_init(silc_client->client)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment