예제 #1
0
파일: client.c 프로젝트: TripleChocPi/LIRC
void lirc_client_connect(struct LIRCServer_struct* server,
                         LIRCSettings* settings, int socket,
                         char* nick)
{
  char temp[MAX_IRC_MESSAGE_SIZE];
  LIRCClientData* client = lirc_client_new_metadata();
  client->socket = socket;
  client->nick = safe_strdup(nick);

  insert_at_front(server->client_list, client, sizeof(client));

  /* Send the client the server name */
  sprintf(temp, ":lirc.org 001 %s :Welcome to %s\r\n", nick, 
          settings->server_name);
  send(socket, temp, strlen(temp), 0);

  /* Send the MOTD */
  sprintf(temp, ":lirc.org 372 %s :%s\r\n", nick, settings->motd);
  send(socket, temp, strlen(temp), 0);

  /* End of MOTD */
  sprintf(temp, ":lirc.org 376 %s :%s\r\n", nick, "End of /MOTD command.");
  send(socket, temp, strlen(temp), 0);

  /* Send a PING out */
  sprintf(temp, "PING :%d\r\n", (int)time(NULL));
  send(socket, temp, strlen(temp), 0);

  /* Set the mode of the user */
  sprintf(temp, ":lirc.org 221 %s +i\r\n", nick);
  send(socket, temp, strlen(temp), 0);
  
  sprintf(temp, ":%s!~%[email protected] MODE %s +i\r\n", client->nick, 
          client->user, nick);
}
예제 #2
0
main() {
  list_t mylist;
  mylist.head = mylist.tail = NULL;
  node_t * old_node;
  node_t * rm_node;
  
  // list creation phase
  insert_at_front(8,  &mylist);
  rm_node = mylist.head;
  insert_at_front(5,  &mylist);
  insert_at_front(1,  &mylist);
  insert_at_front(12, &mylist);
  insert_at_front(3,  &mylist);
  insert_at_front(9,  &mylist);
  insert_at_front(7,  &mylist);
  print_list(&mylist);
  
  // list sort phase
  sort_list( &mylist);
  print_list(&mylist);

  // element removal phase
  remove_element( mylist.head, &mylist );
  remove_element( mylist.head, &mylist );
  remove_element( mylist.tail, &mylist );
  remove_element( rm_node, &mylist );
  print_list(&mylist);
}
예제 #3
0
파일: channel.c 프로젝트: TripleChocPi/LIRC
void lirc_channel_join(struct LIRCServer_struct* server,
                       struct LIRCClientData_struct* client,
                       char *channel)
{
  char temp[MAX_IRC_MESSAGE_SIZE];
  dlnode_t* client_node;
  LIRCChannelData* c = 
    (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == NULL)
  {
    /* The channel doesn't exist in the list so we
     * will need to create one */
    c = lirc_channel_new_metadata();
    c->name = safe_strdup(channel);
    insert_at_front(server->channel_list, c, sizeof(c));
  }

  /* Add this client to the list */
  insert_at_front(c->client_list, client,
                  sizeof(client));

  /* Add a weak reference to the joined channels list of the client */
  insert_at_front(client->channel_list, c, sizeof(c));

  /* Send a response message to all connected clients inside the 
   * channel indicating that a join was made */
  client_node = c->client_list->head;

  sprintf(temp, ":%s!~%[email protected] JOIN %s\r\n", client->nick, client->user, 
          channel);

  while (client_node != NULL)
  {
    struct LIRCClientData_struct *client_node_data = 
      (struct LIRCClientData_struct *)client_node->data;

    send(client_node_data->socket, temp, strlen(temp), 0); 
    client_node = client_node->next;
  } 
}