void chat_remove_from_all (struct htlc_conn *htlc) { struct htlc_chat *chatp, *next; for (chatp = chat_list; chatp; chatp = next) { next = chatp->next; chat_clr(htlc, chatp, 1); if (chat_isset(htlc, chatp, 0)) { chat_clr(htlc, chatp, 0); if (!chatp->nusers) { chat_delete(chatp); } else { struct htlc_conn *htlcp; u_int32_t ref; u_int16_t uid; ref = htonl(chatp->ref); uid = htons(htlc->uid); for (htlcp = htlc_list->next; htlcp; htlcp = htlcp->next) { if (chat_isset(htlcp, chatp, 0)) { hlwrite(htlcp, HTLS_HDR_CHAT_USER_PART, 0, 2, HTLS_DATA_CHAT_ID, sizeof(ref), &ref, HTLS_DATA_UID, sizeof(uid), &uid); } } } } } }
int main() { // Change console appearance. SetConsoleTitle("Chat - Maxim Gonchar Var8"); SMALL_RECT windowSize = { 0, 0, 79, 49 }; SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &windowSize); // Testing module. chat_t *testChat = chat_new("KR_1 chat"); list_t *usersList = chat_getUsersObjects(testChat); chat_printInfo(testChat); puts(""); chat_addUser(testChat, "Maxim", "Gonchar"); chat_addUser(testChat, "Sergei", "Romaniyk"); chat_addUser(testChat, "Fedya", "Andrienko"); printf("Users list:\n%s\n", chat_getUsersList(testChat)); puts(""); printf("This guy will send messages now: \n"); user_t *tempSender = (user_t *) list_getNodeValueByIndex(usersList, 0); user_printInfo(tempSender); msg_t *tempMessage = msg_new("Hello", "World"); user_sendMessageToAll(testChat, tempSender, tempMessage, testCallback); // Free allocated memory. chat_delete(testChat); return 0; }
void rcv_chat_part (struct htlc_conn *htlc) { u_int32_t ref = 0; struct htlc_chat *chat; dh_start(htlc) if (dh_type != HTLC_DATA_CHAT_ID) continue; dh_getint(ref); if ((chat = chat_lookup_ref(ref)) && chat_isset(htlc, chat, 0)) { chat_clr(htlc, chat, 0); if (!chat->nusers) chat_delete(chat); else { struct htlc_conn *htlcp; u_int16_t uid; ref = htonl(ref); uid = htons(htlc->uid); for (htlcp = htlc_list->next; htlcp; htlcp = htlcp->next) if (chat_isset(htlcp, chat, 0)) hlwrite(htlcp, HTLS_HDR_CHAT_USER_PART, 0, 2, HTLS_DATA_CHAT_ID, sizeof(ref), &ref, HTLS_DATA_UID, sizeof(uid), &uid); } } dh_end() }