#include "client.h"
//好友管理模块,实现好友的添加、删除、显示好友列表和在线用户列表。
void friend_manage()
{
char buf[4096];
char ch;
char cmd_str[1024];
int i,j;
u_int32_t ID_other;
char *buf_ptr;
struct message_head m_head;
printf_ui(FRIEND_PAGE);
while (fgets(cmd_str, 1024, stdin)) {
ch = *cmd_str;
if (ch != '\n')
switch (ch) {
case 'a':
case 'A':
printf("Add a friend!\n");
m_head.ctr = ADD_FRIEND;
m_head.dst = 0;
m_head.src = ID_self;
printf("please input ID you want to Add friend's:");
fflush(stdin);
scanf("%u",&ID_other);
buf_ptr = buf;
*(struct message_head *)buf = m_head;
buf_ptr += sizeof(struct message_head);
*(u_int32_t*)buf_ptr = ID_other;
buf_ptr += sizeof(u_int32_t);
tp_send(sock_fd, buf, buf_ptr - buf);
u_friend[num_friend_record].ID = ID_other;
strncpy(u_friend[num_friend_record].name,"user",20);
u_friend[num_friend_record].state = 0;
num_friend_record++;
break;
case 'd':
case 'D':
printf("Delete a frined!\n");
m_head.ctr = DEL_FRIEND;
m_head.dst = 0;
m_head.src = ID_self;
printf("please input ID you want to delete friend's:");
fflush(stdin);
scanf("%u",&ID_other);
buf_ptr = buf;
*(struct message_head *)buf = m_head;
buf_ptr+=12;
*(u_int32_t *)buf_ptr = ID_other;
buf_ptr += 4;
tp_send(sock_fd, buf,buf_ptr-buf);
for (i = 0; i<num_friend_record; i++){
if (u_friend[i].ID == ID_other){
for (j=i; j<num_friend_record; j++)
u_friend[j] = u_friend[j+1];
num_friend_record--;
}
}
break;
case 'l':
case 'L':
printf("Request friends list!\n");
if (num_friend_record == 0)
printf("No friend you have!\n");
printf("ID name\n");
for (i = 0; i < num_friend_record; i++){
printf("%d %s\n",u_friend[i].ID,u_friend[i].name);
}
printf("order:\n");
break;
case 'o':
case 'O':
printf("Request the list of online users!\n");
m_head.ctr = REQ_ONLINE_LIST;
m_head.dst = 0;
m_head.src = ID_self;
*(struct message_head *)buf = m_head;
tp_send(sock_fd, buf,12);
break;
case 'q':
case 'Q':
printf_ui(MAIN_PAGE);
choose_module();
break;
default:
printf("Friend_message:Input error! please input again!\n");
printf("order:\n");
}
}
}
//群管理模块,实现创建群、添加群成员、删除群成员等功能
void group_manage()
{
char buf[4096];
char ch,c;
char send_str[256];
char cmd_str[1024];
u_int32_t ID_other;
u_int32_t ID_group;
char *buf_ptr;
char name[256];
struct message_head m_head;
printf_ui(GROUP_PAGE);
while (fgets(cmd_str, 1024, stdin)) {
ch = *cmd_str;
if (ch != '\n')
switch (ch) {
case 'c':
case 'C':
printf("Create a group.\n");
m_head.ctr = CREATE_GROUP;
m_head.dst = 0;
m_head.src = ID_self;
printf("please input the name of group:");
fflush(stdin);
scanf("%s",name);
name[strlen(name)-1]='\0';
*(struct message_head *)buf = m_head;
buf_ptr = buf;
buf_ptr += 12;
strncpy(buf_ptr, name,20);
buf_ptr += 20;
tp_send(sock_fd, buf,buf_ptr - buf);
break;
case 'a':
case 'A':
printf("Add group members.\n");
m_head.ctr = ADD_MEMBER;
m_head.dst = 0;
m_head.src = ID_self;
printf("please input the ID of group:");
fflush(stdin);
scanf("%u",&ID_group);
printf("please input the ID of user:");
fflush(stdin);
scanf("%u",&ID_other);
buf_ptr = buf;
*(struct message_head *)buf = m_head;
buf_ptr += MESSAGE_HEAD_LEN;
*(u_int32_t *)buf_ptr = ID_group;
buf_ptr += U_INT32_T_LEN;
*(u_int32_t *)buf_ptr = ID_other;
buf_ptr += U_INT32_T_LEN;
tp_send(sock_fd, buf, buf_ptr - buf);
break;
case 'd':
case 'D':
printf("Delete member of group.\n");
m_head.ctr = DEL_MEMBER;
m_head.dst = 0;
m_head.src = ID_self;
printf("please input the ID of group:");
fflush(stdin);
scanf("%u",&ID_group);
printf("please input the ID of user:");
fflush(stdin);
scanf("%u",&ID_other);
buf_ptr = buf;
*(struct message_head *)buf = m_head;
buf_ptr += 12;
*(u_int32_t *)buf_ptr = ID_group;
buf_ptr += 4;
*(u_int32_t *)buf_ptr = ID_other;
buf_ptr += 4;
tp_send(sock_fd,buf,buf_ptr - buf);
break;
case 'm':
case 'M':
printf("Request the list of group member.\n");
m_head.ctr = REQ_GROUP_MEMBER;
m_head.dst = 0;
m_head.src = ID_self;
printf("please input the ID of group:");
fflush(stdin);
scanf("%u",&ID_group);
buf_ptr = buf;
*(struct message_head *)buf = m_head;
buf_ptr += MESSAGE_HEAD_LEN;
*(u_int32_t *)buf_ptr = ID_group;
buf_ptr += U_INT32_T_LEN;
tp_send(sock_fd, buf, buf_ptr - buf);
break;
case 'i':
case 'I':
printf("the group message.\n");
m_head.ctr = SEND_GROUP_INFO;
printf("please input the group ID you want to send message:");
fflush(stdin);
scanf("%u",&ID_group);
m_head.dst = ID_group;
m_head.src = ID_self;
buf_ptr = buf;
*(struct message_head *)buf = m_head;
buf_ptr += 12;
printf("please input message:\n");
c = getchar();
fgets(send_str,512,stdin);
send_str[strlen(send_str)-1]='\0';
strncpy(buf_ptr, send_str, 512);
buf_ptr += 512;
tp_send(sock_fd,buf,buf_ptr - buf);
printf("order:\n");
break;
case 'q':
case 'Q':
没有合适的资源?快使用搜索试试~ 我知道了~
linux系统下chatroom程序
共22个文件
c:13个
h:6个
makefile:2个
需积分: 9 16 下载量 188 浏览量
2012-12-07
10:23:18
上传
评论
收藏 35KB RAR 举报
温馨提示
一个基于linux系统下,用c语言开发的网上聊天程序,可登录注册,直接make编译,可私聊群聊
资源推荐
资源详情
资源评论
收起资源包目录
chatroom.rar (22个子文件)
chatroom
clientchat
client 33KB
print_ui.c 4KB
my_listen.c 9KB
client.h 1KB
progname.c 55B
client.c 7KB
module.c 14KB
proto.h 852B
debug.h 150B
Makefile 348B
serverchat
fn_extend.c 6KB
friend_manage.c 5KB
reg_manage.c 3KB
chat_server.c 7KB
message_manage.c 3KB
head.h 3KB
list.c 2KB
proto.h 948B
group_manage.c 7KB
list.h 1KB
monitor.c 1KB
Makefile 428B
共 22 条
- 1
资源评论
sxp326
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功