Mod aaa-12 Add user file

RCA:
SOL:
修改人:huangxin
检视人:huangxin
This commit is contained in:
黄昕 2019-08-12 18:49:59 +08:00
parent d9ea2ffc20
commit 64dd998d43
2 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,111 @@
#include "offline_user_force.h"
#include "user_auth.h"
#include "redisMq.h"
#include "cjson/cJSON.h"
/* 回调函数-按照userid强制下线用户 */
void offline_userid_func_recv(struct RecvMsg_t *mmsg)
{
if (!mmsg->msg)
{
return;
}
cJSON * root = cJSON_Parse(mmsg->msg);
if (!root)
{
return;
}
int num_ids = cJSON_GetArraySize(root);
int ids[num_ids];
for (int i = 0; i < num_ids; i++)
{
cJSON * uid = cJSON_GetArrayItem(root, i);
if (!uid)
{
cJSON_Delete(root);
return;
}
ids[i] = uid->valueint;
}
reset_online_by_userid(ids, num_ids);
printf("%s,%d,%llu,%s,%d\n", __FUNCTION__, __LINE__, pthread_self(), mmsg->msg, mmsg->len);
freeMsg(mmsg);
}
/* 回调函数-按照groupid强制下线用户 */
void offline_groupid_func_recv(struct RecvMsg_t *mmsg)
{
if (!mmsg->msg)
{
return;
}
cJSON * root = cJSON_Parse(mmsg->msg);
if(!root)
{
return;
}
int num_gids = cJSON_GetArraySize(root);
int gids[num_gids];
for (int i = 0; i < num_gids; i++)
{
cJSON * gid = cJSON_GetArrayItem(root, i);
if (!gid)
{
cJSON_Delete(root);
return;
}
gids[i] = gid->valueint;
}
reset_online_by_groupid(gids);
printf("%s,%d,%llu,%s,%d\n", __FUNCTION__, __LINE__, pthread_self(), mmsg->msg, mmsg->len);
freeMsg(mmsg);
}
/* 消费者订阅 */
void redis_consunmer_usermanager(CONINFO * consumer_info)
{
if(NULL == consumer_info || NULL == consumer_info->topic || NULL == consumer_info->func)
{
printf("redis_consunmer_usermanager -> NULL");
return;
}
bool ret = redisSubInit(8);
if (!ret)
{
//printf("Init failed.\n");
return;
}
redisRegisterChannelFunc(consumer_info->topic,consumer_info->func);
ret = redisSubConnect();
if (!ret)
{
//printf("Connect failed.\n");
return;
}
redisSubscriber(consumer_info->topic);
while (true)
{
sleep(1);
}
redisSubDisconnect();
redisSubUninit();
return;
}
/* */

View File

@ -0,0 +1,19 @@
#ifndef OFFLINE_USER_FROCE_H_
#define OFFLINE_USER_FROCE_H_
#include "redisMq.h"
typedef struct consumer_info
{
char * topic; //订阅频道
pChanneCallBack func; //回调函数
}CONINFO;
/* 消费者订阅-按用户ID或用户组id下线 */
void redis_consunmer_usermanager(CONINFO * consumer_info);
/* 按ip下线用户 */
#endif