示例#1
0
文件: home.c 项目: Zhanyin/taomee
static int proto_cli_leave_home_op(home_t* p_home, sprite_ol_t* p, void* data)
{
	hero_cup_game_t* game = NULL;
	home_proto_t* p_proto = data;
	client_proto_t *cli = (client_proto_t*)p_proto->body;
	CHECK_BODY_LEN(p_proto->len, 20 + sizeof(home_proto_t) + sizeof(client_proto_t));

	int i = 12;
	mapid_t newmap = 0;
	unpkg_mapid(cli->body,&newmap,&i);
	mapid_t gameid = (p_home->homeid & 0xFFFFFFFF00000000) | hero_cup_game_map;

	tranfer_to_home(p_home, data, p_proto->len);
	free_sprite_ol(p_home, p);

	if((gameid >> 56) != 0xFE) return 0;
	game = g_hash_table_lookup(all_games,&gameid);
	if(!game) {
		KDEBUG_LOG(p_proto->id,"LEAVE HOME: game(%x.%u) NOT EXSIT!",HI32(gameid),LO32(gameid));
		return 0;
	}

	game->active--;
	if((newmap >> 56) != 0xFE) {
		if(game->active == 0) {
			free_game(NULL,game,NULL);
			return 0;
		}
	}

	attacker_t *atker = get_attacker(game,p_proto->id);
	if(!atker) {
		KDEBUG_LOG(p_proto->id,"LEAVE HOME: uid not in game(%x.%u)",HI32(gameid),LO32(gameid));
		return 0;
	}

	if(atker->atkpos < 12) {
		position_t *weapon = &game->weapon[atker->atkpos];
		if(weapon->uid == atker->userid) {
			weapon->state |= 1;
			weapon->card = 0;
		} else {
			weapon->state |= 2;
			weapon->atk_card = 0;
		}
		play_card_result(game,atker->atkpos);
	}

	if((newmap >> 56) != 0xFE) {
		del_attacker(game->group,atker->userid);
	}

	return 0;
}
示例#2
0
int64_t FSeek(HANDLE h, int64_t pos, int method)
{
  LONG hi32 = HI32(pos);
  LONG lo32 = ::SetFilePointer(h, LO32(pos), &hi32, method);
  if (lo32 == INVALID_SET_FILE_POINTER && ::GetLastError())
    return -1;
  else
    return MAKEINT64(lo32, hi32);
}
示例#3
0
文件: home.c 项目: Zhanyin/taomee
void free_sprite_ol(home_t* h, sprite_ol_t* p)
{
	userid_t uid = p->id;
	del_online_user(h, p->onlineid);	
	g_hash_table_remove(h->sprites, &uid);
	g_slice_free1(SPRITE_OL_STRUCT_LEN, p);
	if (0 == g_hash_table_size(h->sprites)) {
		KDEBUG_LOG(uid,"FREE HOME: [homeid=%x %u]", HI32(h->homeid),LO32(h->homeid));
		free_home(h);
	}
}
示例#4
0
status_t
AHCIPort::FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax,
                       const physical_entry *sgTable, int sgCount, size_t dataSize)
{
    *prdCount = 0;
    while (sgCount > 0 && dataSize > 0) {
        size_t size = min_c(sgTable->size, dataSize);
        phys_addr_t address = sgTable->address;
        T_PORT(AHCIPortPrdTable(fController, fIndex, address, size));
        FLOW("FillPrdTable: sg-entry addr %#" B_PRIxPHYSADDR ", size %lu\n",
             address, size);
        if (address & 1) {
            TRACE("AHCIPort::FillPrdTable: data alignment error\n");
            return B_ERROR;
        }
        dataSize -= size;
        while (size > 0) {
            size_t bytes = min_c(size, PRD_MAX_DATA_LENGTH);
            if (*prdCount == prdMax) {
                TRACE("AHCIPort::FillPrdTable: prd table exhausted\n");
                return B_ERROR;
            }
            FLOW("FillPrdTable: prd-entry %u, addr %p, size %lu\n",
                 *prdCount, address, bytes);

            prdTable->dba = LO32(address);
            prdTable->dbau = HI32(address);
            prdTable->res = 0;
            prdTable->dbc = bytes - 1;
            *prdCount += 1;
            prdTable++;
            address = address + bytes;
            size -= bytes;
        }
        sgTable++;
        sgCount--;
    }
    if (*prdCount == 0) {
        TRACE("AHCIPort::FillPrdTable: count is 0\n");
        return B_ERROR;
    }
    if (dataSize > 0) {
        TRACE("AHCIPort::FillPrdTable: sg table %ld bytes too small\n",
              dataSize);
        return B_ERROR;
    }
    return B_OK;
}
示例#5
0
文件: home.c 项目: Zhanyin/taomee
int proto_enter_home_op(home_proto_t* p_proto)
{
	hero_cup_game_t *game = NULL;
	mapid_t gameid = (p_proto->homeid & 0xFFFFFFFF00000000) | hero_cup_game_map;
	CHECK_BODY_LEN_GE(p_proto->len, sizeof(home_proto_t) + sizeof(sprite_base_info_t));

	KDEBUG_LOG(p_proto->id,"ENTER HOME: [homeid=%x %u]", HI32(p_proto->homeid), LO32(p_proto->homeid));

	home_t* p_home	= g_hash_table_lookup(all_home, &p_proto->homeid);
	if((gameid >> 56) == 0xFE) game = g_hash_table_lookup(all_games,&gameid);
	if(!p_home) {
		if(HI32(p_proto->homeid) == 1 || game) p_home	= add_home(p_proto->homeid);
		if (!p_home) {
			KDEBUG_LOG(p_proto->id,"ENTER HOME FAILED [onlineid=%u map=%x %u]",p_proto->onlineid, HI32(p_proto->homeid), LO32(p_proto->homeid));
			return 0;
		}
	}

	sprite_ol_t* p = g_hash_table_lookup(p_home->sprites, &p_proto->id);
	if (!p) {
		p = add_sprite_ol(p_home, p_proto);
		if (!p) {
			KDEBUG_LOG(p_proto->id,"ADD PLAYER FAILED [onlineid=%u map=%x %u]", p_proto->onlineid,HI32(p_proto->homeid), LO32(p_proto->homeid));
			return 0;
		}
		if(game) {
			game->active++;
			KDEBUG_LOG(p_proto->id,"ENTER HOME: have %d players in game(%x)",game->active,HI32(gameid));
		}
	}

	memcpy(&p->sprite_info, p_proto->body, sizeof(sprite_base_info_t));
	if (p->sprite_info.pet_followed) {
		memcpy(&p->pet_sinfo, p_proto->body + sizeof(sprite_base_info_t), sizeof(pet_simple_info_t));
	}

	send_all_users_to_self(p->id, p->onlineid, p_home);
	return 0;
}
示例#6
0
文件: home.cpp 项目: Zhanyin/taomee
int proto_enter_home_op(home_proto_t* p_proto)
{
	CHECK_BODY_LEN_GE(p_proto->len, sizeof(home_proto_t) + sizeof(sprite_base_info_t));

	KDEBUG_LOG(p_proto->id,"ENTER HOME: [homeid=%x %u]", HI32(p_proto->homeid), LO32(p_proto->homeid));

	home_t* p_home	= (home_t*)g_hash_table_lookup(all_home, &p_proto->homeid);
    if(!p_home) {
        p_home   = add_home(p_proto->homeid);
        if (!p_home) {
            KDEBUG_LOG(p_proto->id,"ENTER HOME FAILED [onlineid=%u map=%x %u]",p_proto->onlineid, HI32(p_proto->homeid), LO32(p_proto->homeid));
            return 0;
        }
    }

	sprite_ol_t* p =(sprite_ol_t*) g_hash_table_lookup(p_home->sprites, &p_proto->id);
	if (!p) {
		p = add_sprite_ol(p_home, p_proto);
		if (!p) {
			KDEBUG_LOG(p_proto->id,"ADD PLAYER FAILED [onlineid=%u map=%x %u]", p_proto->onlineid,HI32(p_proto->homeid), LO32(p_proto->homeid));
			return 0;
		}
	}

	memcpy(&p->sprite_info, p_proto->body, sizeof(sprite_base_info_t));
	if (p->sprite_info.pet_followed) {
		memcpy(&p->pet_sinfo, p_proto->body + sizeof(sprite_base_info_t), sizeof(pet_simple_info_t));
	}

	send_all_users_to_self(p->id, p->onlineid, p_home);

	//pvp 处理	
	g_pvp[0].cd_map(p_proto->homeid, p->id );
	g_pvp[1].cd_map(p_proto->homeid, p->id );
	//trade 进入交易房间
    g_market.cd_room(p->id);
	return 0;
}
示例#7
0
status_t
AHCIPort::Init1()
{
    TRACE("AHCIPort::Init1 port %d\n", fIndex);

    size_t size = sizeof(command_list_entry) * COMMAND_LIST_ENTRY_COUNT
                  + sizeof(fis) + sizeof(command_table)
                  + sizeof(prd) * PRD_TABLE_ENTRY_COUNT;

    char *virtAddr;
    phys_addr_t physAddr;

    fArea = alloc_mem((void **)&virtAddr, &physAddr, size, 0,
                      "some AHCI port");
    if (fArea < B_OK) {
        TRACE("failed allocating memory for port %d\n", fIndex);
        return fArea;
    }
    memset(virtAddr, 0, size);

    fCommandList = (command_list_entry *)virtAddr;
    virtAddr += sizeof(command_list_entry) * COMMAND_LIST_ENTRY_COUNT;
    fFIS = (fis *)virtAddr;
    virtAddr += sizeof(fis);
    fCommandTable = (command_table *)virtAddr;
    virtAddr += sizeof(command_table);
    fPRDTable = (prd *)virtAddr;
    TRACE("PRD table is at %p\n", fPRDTable);

    fRegs->clb  = LO32(physAddr);
    fRegs->clbu = HI32(physAddr);
    physAddr += sizeof(command_list_entry) * COMMAND_LIST_ENTRY_COUNT;
    fRegs->fb   = LO32(physAddr);
    fRegs->fbu  = HI32(physAddr);
    physAddr += sizeof(fis);
    fCommandList[0].ctba  = LO32(physAddr);
    fCommandList[0].ctbau = HI32(physAddr);
    // prdt follows after command table

    // disable transitions to partial or slumber state
    fRegs->sctl |= 0x300;

    // clear IRQ status bits
    fRegs->is = fRegs->is;

    // clear error bits
    fRegs->serr = fRegs->serr;

    // power up device
    fRegs->cmd |= PORT_CMD_POD;

    // spin up device
    fRegs->cmd |= PORT_CMD_SUD;

    // activate link
    fRegs->cmd = (fRegs->cmd & ~PORT_CMD_ICC_MASK) | PORT_CMD_ICC_ACTIVE;

    // enable FIS receive
    fRegs->cmd |= PORT_CMD_FER;

    FlushPostedWrites();

    return B_OK;
}
示例#8
0
W64 sys_seek(int fd, W64 offset, unsigned int origin) {
  loff_t newoffs;
  int rc = sys_llseek(fd, HI32(offset), LO32(offset), &newoffs, origin);
  return (rc < 0) ? rc : newoffs;
}
示例#9
0
inline int dispatcher(void* data, fdsession_t* fdsess)
{
	char version[256] = {0};
	home_proto_t* proto = data;

	if(proto->cmd == proto_get_version) {
		proto = (home_proto_t*)version;
		proto->len = 256;
		strncpy((char*)proto->body,g_version,200);
		return send_pkg_to_client(fdsess, proto, 256);
	}

	if (proto->onlineid > MAX_ONLINE_NUM) {
		KERROR_LOG(proto->id,"invaild onlineid=%u", proto->onlineid);
		return -1;
	}

	if ((proto->opid <= proto_begin) || (proto->opid >= proto_max)) {
		KERROR_LOG(proto->id, "invalid opid [len=%u cmd=%u onineid=%u homeid=%u opid=%u]",proto->len,proto->cmd,proto->onlineid,(uint32_t)proto->homeid,proto->opid);
		return -1;
	}

	all_fds[proto->onlineid] = fdsess;

	switch(proto->opid) {
		case proto_join_group:
			return join_hero_cup_op(proto);
		case proto_cancel_group:
			return cancel_hero_cup_op(proto);
		case proto_enter_home:
			return proto_enter_home_op(proto);
	}

	home_t* p_home	= g_hash_table_lookup(all_home, &proto->homeid);
	if (!p_home) {
		KDEBUG_LOG(proto->id,"MAP NOT EXSIT[onlineid=%u mapid=(%x,%u) opid=%u]",proto->onlineid,HI32(proto->homeid),LO32(proto->homeid),proto->opid);
		return 0;
	}
	sprite_ol_t* p = g_hash_table_lookup(p_home->sprites, &proto->id);
	if(!p) {
		KDEBUG_LOG(proto->id,"PLAYER NOT EXSIT[onlineid=%u mapid=(%x,%u) opid=%u]",proto->onlineid,HI32(proto->homeid),LO32(proto->homeid),proto->opid);
		return 0;
	}

	return handle_online_op(p_home, p, proto);
}