Exemple #1
0
void cmd_login(struct conn_server *server, struct connection *conn,
		struct list_packet *packet)
{
	conn->type = LOGIN_UNCOMPLETE_CONNECTION;
	conn->uin = get_uin(packet);
	/* NOTE: this is used for test */
	struct uin_entry *uin_entry = malloc(sizeof(struct uin_entry));
	uin_entry->uin = conn->uin;
	uin_entry->conn = conn;
	HASH_ADD_INT(server->uin_conn_map, uin, uin_entry);

	cmd_user(server, conn, packet);
}
Exemple #2
0
int		my_cmd(char **com, int const cfd)
{
  if (strcmp(com[0], "/user") == 0)
    cmd_user(com, cfd);
  else if (strcmp(com[0], "/nick") == 0)
    cmd_nick(com, cfd);
  else if (strcmp(com[0], "/join") == 0)
    {
      if (cmd_join(com, cfd) == -1)
	return (-1);
    }
  else
    my_cmd2(com, cfd);
  return (0);
}
Exemple #3
0
void
cmd_checkuser(void)
{
	uint8_t buf[DIRREC], *p;
	static char utime[4];

	if(con_clone(FID1, FID2)
	|| con_path(FID2, "/adm/users")
	|| con_open(FID2, 0)
	|| con_stat(FID2, (char*)buf))
		return;
	p = buf + 3*NAMELEN + 4*4;
	if(memcmp(utime, p, 4) == 0)
		return;
	memmove(utime, p, 4);
	cmd_user();
}
Exemple #4
0
/* handler invoked by readline when input is submitted with enter */
static void tty_executor( char *input )
{
	char *c;
	int len;

	/* readline got EOF */
	if( ! input ){
		terminate++;
		return;
	}

	/* empty command */
	if( ! *input ){
		free( input );
		return;
	}

	/* strip trailing whitespace */
	for( c = input + strlen(input) - 1; c != input && isspace(*c); --c )
		*c = 0;

	add_history(input);

	/* execute action - if one is defined */

	len = strcspn( input, "\t " );
	if( 0 == strcasecmp( input, "quit" ) ){
		terminate++;

	} else if( 0 == strcasecmp( input, "exit" ) ){
		terminate++;

	} else if( len ==4 && 0 == strncasecmp( input, "user", 4 ) ){
		cmd_user( input +4 );

	} else {
		duc_cmd( con, input );
	}

	free(input);
}
Exemple #5
0
/* client packet handler */
void cmd_packet_handler(struct conn_server *server, struct connection *conn,
		struct list_packet *packet)
{
	uint16_t command = get_command(packet);
	/* check login status */
	if (conn->type != LOGIN_OK_CONNECTION &&
			command != CMD_LOGIN) {
		/* the client not login, ignore this packet */
		allocator_free(&server->packet_allocator, packet);
		return;
	}

	switch (command) {
	case CMD_KEEP_ALIVE:
		cmd_keep_alive(server, conn, packet);
		break;
	case CMD_LOGIN:
		cmd_login(server, conn, packet);
		break;
	case CMD_LOGOUT:
		cmd_logout(server, conn, packet);
		break;
	case CMD_SET_NICK:
		cmd_user(server, conn, packet);
		break;
	case CMD_ADD_CONTACT:
	case CMD_ADD_CONTACT_REPLY:
	case CMD_CONTACT_LIST:
	case CMD_CONTACT_INFO_MULTI:
		cmd_contact(server, conn, packet);
		break;
	case CMD_MESSAGE:
	case CMD_OFFLINE_MSG:
		cmd_message(server, conn, packet);
		break;
	default:
		log_err("unkonwn command %#hx\n", command);
		break;
	}
}