コード例 #1
0
ファイル: area.cpp プロジェクト: Gamesjiazhi/rwproject
//-----------------------------------------------------------------------------
// area_sendactorinfo
// 函数说明: 发送指定坐标位置所关联的区域中的所有NPC和玩家的信息(不包括队友)
//           给指定socket,还应当有所有角色的移动目的地信息,和玩家的状态信息(暂时没有)
//           玩家进入游戏,和战斗结束的恢复时候获取NPC信息
// 参数    : client_index -
//           mapid -
//           posx -
//           posy -
// 返回值  : int
//-----------------------------------------------------------------------------
int area_sendunitinfo( int client_index, int posx, int posy )
{
    int areax, areay;
    int tmpx,tmpy,next_index;
    int area_index;
    int cur_index;

    char msg[2048] = {0};
    int size = 0;

    areax = posx/AREA_WIDTH;
    areay = posy/AREA_HEIGHT;

    for( tmpx = areax-1; tmpx <= areax+1; tmpx++ )
    {
        if( tmpx < 0 || tmpx >=g_map.m_nAreaXNum )
            continue;
        for( tmpy = areay-1; tmpy <= areay+1; tmpy++ )
        {
            if( tmpy < 0 || tmpy >=g_map.m_nAreaYNum )
                continue;
            area_index = area_getindex_fromgrid(tmpx, tmpy);

            cur_index = g_map.m_aArea[area_index].unit_head;
            while( cur_index >= 0 )
            {
                next_index = g_mapunit[cur_index].next_index;
                // process
                if( cur_index < 0 )
                {
                    cur_index = next_index;
                    continue;
                }
                if ( g_mapunit[cur_index].type == 0 )
                {
                    cur_index = next_index;
                    continue;
                }
                if ( mapunit_enterinfo( cur_index, msg + sizeof(short), &size ) < 0 )
                {
                    *(unsigned short *)msg = size;
                    sendtoclient( client_index, msg, size+sizeof(short) );
//					write_gamelog( "[size:%d][actor_enterinfo]", size );
                    memset( msg, 0, 2048 );
                    size = 0;
                    mapunit_enterinfo( cur_index, msg + sizeof(short), &size );
                }
                cur_index = next_index;
            }
        }
    }

    if( size > 0 )
    {
        *(unsigned short *)msg = size;
        sendtoclient( client_index, msg, size+sizeof(short) );
        write_gamelog( "[size:%d][AREA_GETACTORINFO][%d]", size, g_mapunit[client_index].type );
    }
    return 0;
}
コード例 #2
0
ファイル: syncd_cli.cpp プロジェクト: kcudnik/sonic-sairedis
void handle_cli_commands(const std::string& line)
{
    SWSS_LOG_ENTER();

    SWSS_LOG_NOTICE("cli: %s", line.c_str());

    // TODO this must be more smart, to split multiple spaces
    auto tokens = swss::tokenize(trim(line), ' ');

    if (tokens.size() < 1)
    {
        return;
    }

    const std::string& cmd = tokens[0];

    if (cmd == "exit" || cmd == "quit")
    {
        cmd_exit();
    }
    else if (cmd == "loglevel")
    {
        cmd_loglevel(tokens);
    }
    else if (cmd == "help")
    {
        cmd_help(tokens);
    }
    else
    {
        sendtoclient("unknown command: " + line + "\n");
    }
}
コード例 #3
0
ファイル: actor_send.cpp プロジェクト: Gamesjiazhi/rwproject
int actor_senddata( int actor_index, char send_type, char *data, int datasize )
{
	switch( send_type )
	{
	case SENDTYPE_ACTOR:
		sendtoclient( actor_index, data, datasize+sizeof(short) );
		break;
	case SENDTYPE_FIGHT:
		break;
	case SENDTYPE_TEAM:
		break;
	case SENDTYPE_FIGHTAREA:
		break;
	case SENDTYPE_AREA:
		{
			int area_index = g_actors[actor_index].view_areaindex;
			area_sendmsg( area_index, datasize, data + sizeof(short) );
			area_clearmsg( area_index );
		}
		break;
	case SENDTYPE_NPCAREA:
		break;
	case SENDTYPE_MAP:
		break;
	case SENDTYPE_WORLD:
		world_sendmsg( datasize, data );
		break;
	case SENDTYPE_CLUB:
		break;
	case SENDTYPE_WORLD_WITHOUT:
		//world_without_sendmsg( datasize, data );
		break;
	}
	return 0;
}
コード例 #4
0
ファイル: syncd_cli.cpp プロジェクト: kcudnik/sonic-sairedis
void cmd_exit()
{
    SWSS_LOG_ENTER();

    run_user = false;

    sendtoclient("bye\n");
}
コード例 #5
0
ファイル: area.cpp プロジェクト: Gamesjiazhi/rwproject
// 一个玩家移动屏幕离开区域需要获得区域离开的数据
int area_leave( int actor_index, int area_index )
{
    int cur_index;
    int next_index;

    char msg[2048] = {0};
    int size = 0;
    if ( area_index < 0 )
        return -1;
    // 把区域中的单元组合离开的消息传送给自己
    cur_index = g_map.m_aArea[area_index].unit_head;
    while( cur_index >= 0 )
    {
        next_index = g_mapunit[cur_index].next_index;
        if( cur_index < 0 )
        {
            cur_index = next_index;
            continue;
        }
        if ( g_mapunit[cur_index].type == 0 )
        {
            cur_index = next_index;
            continue;
        }
        // 组织数据包
        if ( mapunit_leaveinfo( cur_index, msg + sizeof(short), &size ) < 0 )
        {
            *(unsigned short *)msg = size;
            // 发送给自己
            sendtoclient( actor_index, msg, size + sizeof(short) );
            memset( msg, 0, 2048 );
            size = 0;
            mapunit_leaveinfo( cur_index, msg + sizeof(short), &size );
        }
        cur_index = next_index;
    }

    if( size > 0 )
    {
        *(unsigned short *)msg = size;
        // 发送给自己
        sendtoclient( actor_index, msg, size + sizeof(short) );
    }
    return 0;
}
コード例 #6
0
ファイル: syncd_cli.cpp プロジェクト: kcudnik/sonic-sairedis
void cmd_loglevel(const std::vector<std::string>& args)
{
    SWSS_LOG_ENTER();

    if (args.size() < 2)
    {
        sendtoclient("missing level parameter\n");
        return;
    }

    std::string slevel = args[1];

    std::transform(slevel.begin(), slevel.end(), slevel.begin(), ::toupper);

    swss::Logger::Priority level = swss::Logger::stringToPriority(slevel);

    swss::Logger::getInstance().setMinPrio(level);

    sendtoclient("log level changed to " + swss::Logger::priorityToString(level) + "\n");
}
コード例 #7
0
ファイル: syncd_cli.cpp プロジェクト: kcudnik/sonic-sairedis
void cmd_help(const std::vector<std::string>& args)
{
    SWSS_LOG_ENTER();

    std::string help = "\n\
    help            - this command\n\
    exit            - close cli connection\n\
    loglevel LEVEL  - sets debug logger level\n\n";

    sendtoclient(help);
}
コード例 #8
0
ファイル: area.cpp プロジェクト: Gamesjiazhi/rwproject
// 区域即时发送, 仅仅发送给指定区域中的角色, 关联区域不会发送
// 内部使用函数, 在actors_enterarea和actors_leavearea中使用, 如有区域信息使用area_sendmsg函数
int area_send( int area_index, int datasize, char *databuf )
{
    int tmpi;
    for ( tmpi = 0; tmpi < g_maxactornum; tmpi++ )
    {
        if ( g_actors[tmpi].actorid > 0 && g_actors[tmpi].view_areaindex == area_index )
        {
            sendtoclient( tmpi, databuf, datasize );
        }
    }

    return 0;
}
コード例 #9
0
ファイル: actor_send.cpp プロジェクト: Gamesjiazhi/rwproject
// 世界信息发送,信息立即发送
int world_sendmsg( int datasize, char *databuf )
{
	int tmpi;
	if ( datasize > 0 )
	{
		for ( tmpi = 0; tmpi < g_maxactornum; tmpi++ )
		{
			if ( g_actors[tmpi].actorid > 0 )
				sendtoclient( tmpi, databuf, datasize + sizeof(short) );
		}
	}
	return 0;
}
コード例 #10
0
ファイル: area.cpp プロジェクト: Gamesjiazhi/rwproject
//-----------------------------------------------------------------------------
// area_clearmsg
// 函数说明: 清除区域数据,将区域数据发送给所有本区域玩家
// 参数    : mapid -
//           area_index -
// 返回值  : int
//-----------------------------------------------------------------------------
int area_clearmsg( int area_index )
{
    int areax, areay;
    int tmpx, tmpy;
    int other_area_index;
    int pos;
    Area *pArea;

    if ( g_map.m_nAreaXNum == 0 )
        return 0; // 如果有除0的可能就返回
    area_getoffset(area_index, &areax, &areay);

    pArea = &g_map.m_aArea[area_index];
    pos = pArea->pos == 0? 1 : 0;

    if( pArea->actor_size[pos] < 0 )
        pArea->actor_size[pos] = 0;

    if( pArea->actor_size[pos] <= 0 )
    {
        pArea->pos = pos;
        return 1;
    }

    for( tmpx = areax-1; tmpx <= areax+1; tmpx++ )
    {
        if( tmpx < 0 || tmpx >=g_map.m_nAreaXNum )
            continue;
        for( tmpy = areay-1; tmpy <= areay+1; tmpy++ )
        {
            if( tmpy < 0 || tmpy >=g_map.m_nAreaYNum )
                continue;
            other_area_index = area_getindex_fromgrid(tmpx, tmpy);

            for (int tmpi = 0; tmpi < g_maxactornum; tmpi++)
            {
                if (g_actors[tmpi].actorid > 0 && g_actors[tmpi].view_areaindex == other_area_index)
                {
                    *(unsigned short *)pArea->actor_msg[pos] = pArea->actor_size[pos];
                    sendtoclient(tmpi, pArea->actor_msg[pos], pArea->actor_size[pos] + sizeof(unsigned short));
                }
            }
        }
    }
    pArea->actor_size[pos] = 0;
    pArea->pos = pos;
    return 0;
}
コード例 #11
0
ファイル: syncd_cli.cpp プロジェクト: kcudnik/sonic-sairedis
void handle_cli()
{
    SWSS_LOG_ENTER();

    char buffer[BUFFER_SIZE];

    run_user = true;

    while (run_user)
    {
        if (!sendtoclient(CLI_PROMPT))
        {
            return;
        }

        // blocking
        ssize_t n = read(cli_client_socket, buffer, BUFFER_SIZE);

        if (n == 0)
        {
            SWSS_LOG_NOTICE("stream closed");
            return;
        }

        if (n < 0)
        {
            if (run_cli || run_user)
            {
                SWSS_LOG_ERROR("read failed, errno: %s", strerror(errno));
            }

            return;
        }

        const std::string& s = std::string(buffer, n);

        handle_cli_commands(s);
    }
}
コード例 #12
0
ファイル: client.c プロジェクト: skynete10/store-php
int main(int argc, char **argv) {
int sockfd, userlen;
memset(&me, 0, sizeof(struct USER));
while(gets(option)) {
if(!strncmp(option, "exit", 4)) {
logout(&me);
break;
}
else if(!strncmp(option, "login", 5)) {
char *ptr = strtok(option, " ");
ptr = strtok(0, " ");//set ptr as username
memset(me.user, 0, sizeof(char) * userLEN);
if(ptr != NULL) {
userlen = strlen(ptr);//strlen:calcule la longeur du chaine de caractere
if(userlen > userLEN) ptr[userLEN] = 0;
strcpy(me.user, ptr);//copy ptr in me.user
}
else {

strcpy(me.user, "default");//copy default to me.user



}
login(&me);
}
else if(!strncmp(option, "change", 6)) {
char *ptr = strtok(option, " ");
ptr = strtok(0, " ");
memset(me.user, 0, sizeof(char) * userLEN);
if(ptr != NULL) {
userlen = strlen(ptr);
if(userlen > userLEN) ptr[userLEN] = 0;
strcpy(me.user, ptr);
setuser(&me);
}
}
else if(!strncmp(option, "specf", 5)) {
char *ptr = strtok(option, " ");
char temp[userLEN];
ptr = strtok(0, " ");
memset(temp, 0, sizeof(char) * userLEN);
if(ptr != NULL) {
userlen = strlen(ptr);
if(userlen > userLEN) ptr[userLEN] = 0;
strcpy(temp, ptr);
while(*ptr) ptr++; ptr++;
while(*ptr <= ' ') ptr++;
sendtoclient(&me, temp, ptr);
}
}
else if(!strncmp(option, "sfile", 5)) {
char *ptr = strtok(option, " ");
char temp[userLEN];
char *buff;
ptr = strtok(0, " ");
memset(temp, 0, sizeof(char) * userLEN);
if(ptr != NULL) {
userlen = strlen(ptr);
if(userlen > userLEN) ptr[userLEN] = 0;
strcpy(temp, ptr);
while(*ptr) ptr++; ptr++;
while(*ptr <= ' ') ptr++;
sendfile(&me, temp, ptr,buff);
}
}
else if(!strncmp(option, "encrypt", 7)) {
char *ptr = strtok(option, " ");
char temp[userLEN];
ptr = strtok(0, " ");
memset(temp, 0, sizeof(char) * userLEN);
if(ptr != NULL) {
userlen = strlen(ptr);
if(userlen > userLEN) ptr[userLEN] = 0;
strcpy(temp, ptr);
while(*ptr) ptr++; ptr++;
while(*ptr <= ' ') ptr++;
sendencrypt(&me, temp, ptr);
}
}
else if(!strncmp(option, "broadcast", 9)) {
sendtoall(&me, &option[9]);
}
else if(!strncmp(option, "list", 4)) {

}
else if(!strncmp(option, "logout", 6)) {
logout(&me);
}
else fprintf(stderr, "Unknown option...\n");
}
return 0;
}