示例#1
0
文件: string.c 项目: fy0/python_lite
PyLiteStrObject* pylt_obj_str_new(PyLiteInterpreter *I, uint32_t *str, int size, bool is_raw) {
    PyLiteStrObject *obj = pylt_malloc(I, sizeof(PyLiteStrObject));
    obj->ob_type = PYLT_OBJ_TYPE_STR;
    obj->ob_flags = 0;  
    obj->ob_val = pylt_malloc(I, sizeof(uint32_t) * (size + 1));
    if (is_raw) {
        obj->ob_size = size;
        for (int i = 0; i < size; i++) {
            obj->ob_val[i] = str[i];
        }
        obj->ob_val[size] = '\0';
    } else {
        int pos = 0, num;
        for (int i = 0; i < size;) {
            switch (str[i]) {
                case '\\':
                    if (++i >= size) goto _def;
                    switch (str[i]) {
                        case 'a': obj->ob_val[pos++] = 7; i++; break;
                        case 'b': obj->ob_val[pos++] = 8; i++; break;
                        case 'f': obj->ob_val[pos++] = 12; i++; break;
                        case 'n': obj->ob_val[pos++] = 10; i++; break;
                        case 'r': obj->ob_val[pos++] = 13; i++; break;
                        case 't': obj->ob_val[pos++] = 9; i++; break;
                        case 'v': obj->ob_val[pos++] = 11; break;
                        case '\\': obj->ob_val[pos++] = '\\'; break;
                        case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
							obj->ob_val[pos++] = _read_x_int(str + i, 8, _oct, &num, min(size - i, 3));
                            i += num;
                            break;
                        case 'x':
                            i++;
                            if ((size - i >= 2) && (_ishex(str[i]) && _ishex(str[i + 1]))) {
                                obj->ob_val[pos++] = _hex(str[i]) * 16 + _hex(str[i + 1]);
                            } else {
                                pylt_obj_str_free(I, obj);
                                return NULL;
                            } 
                            i += 2;
                            break;
                        default:
                            if (str[++i] >= 0x80) {
                                // error
                                return NULL;
                            }
                            obj->ob_val[pos++] = '\\';
                            obj->ob_val[pos++] = str[i];
                            break;
                    }
					break;
                default: _def :
                    obj->ob_val[pos++] = str[i++];
            }
        }
        obj->ob_val = pylt_realloc(I, obj->ob_val, sizeof(uint32_t) * size, sizeof(uint32_t) * (size + 1));
        obj->ob_val[pos] = '\0';
        obj->ob_size = pos;
    }
    return hash_and_check_cache(I, obj);
}
示例#2
0
文件: urlparse.c 项目: geocar/winback
static void _decode(char *s)
{
	char *d;
	int a,b;
	if (!s) return;

	/* always gets shorter */
	d=s;
	while (*s) {
		if (*s == '%' && s[1] && s[2]) {
			a = _hex(s[1]);
			b = _hex(s[2]);
			if (a > -1 && b > -1) {
				*d = (a << 4) | b;
				d++;
				s += 3;
				continue;
			}
		}
		if (s != d) *d = *s;
		s++;
		d++;
	}
	if (s != d) *d = *s;
}
示例#3
0
void dumpH264AvcNalUnits (PagePool::Page *page,
                          size_t          msg_offs,
                          size_t          msg_len)
{
    Size const msg_csum = calculateChecksumPages (page, msg_offs, msg_len);
    logD_ (_func, "msg_offs ", msg_offs, ", msg_len ", msg_len, ", msg_csum " _hex (msg_csum));

    for (;;) {
        if (msg_len == 0)
            break;

        if (msg_len < 4) {
            logD_ (_func, "WARNING: discarding ", msg_len, " bytes");
            break;
        }

        while (page->data_len <= msg_offs) {
            msg_offs -= page->data_len;
            page = page->getNextMsgPage();
        }

        PagePool::PageListArray pl_arr (page, msg_offs, msg_len);

        Byte nal_len_buf [4];
        pl_arr.get (/*offset=*/ 0, Memory::forObject (nal_len_buf));
        Uint32 const nal_len = readBe32 (nal_len_buf);

        if (msg_offs + 4 < msg_offs) {
            logD_ (_func, "WARNING: integer overflow, msg_offs ", msg_offs);
            break;
        }
        msg_offs += 4;

        while (page->data_len <= msg_offs) {
            msg_offs -= page->data_len;
            page = page->getNextMsgPage();
        }

        msg_len -= 4;
        if (nal_len > msg_len) {
            logD_ (_func, "WARNING: invalid nal_len ", nal_len, ", msg_len ", msg_len);
            break;
        }
        msg_len -= nal_len;

        {
            assert (page->data_len > msg_offs);
            Byte const nal_type = page->getData() [msg_offs] & 0x1f;

            Size const nal_csum = calculateChecksumPages (page, msg_offs, nal_len);
            logD_ (_func, "NAL unit: nal_type ", nal_type, ", nal_len ", nal_len, ", nal_csum 0x", fmt_hex, nal_csum);
        }

        if (msg_offs + nal_len < msg_offs) {
            logD_ (_func, "WARNING: integer overflow, msg_offs ", msg_offs, ", nal_len ", nal_len);
            break;
        }
        msg_offs += nal_len;
    }
}
示例#4
0
EQRawApplicationPacket *EQStream::MakeApplicationPacket(const unsigned char *buf, uint32 len)
{
	EQRawApplicationPacket *ap=NULL;
	_log(NET__APP_CREATE, _L "Creating new application packet, length %d" __L, len);
	_hex(NET__APP_CREATE_HEX, buf, len);
	ap = new EQRawApplicationPacket(buf, len);
	return ap;
}
示例#5
0
static void nlmsg_print_raw(struct nlmsghdr *hdr)
{
	u32 len = hdr->nlmsg_len;

	if (len) {
		_ascii((uint8_t *) hdr + NLMSG_HDRLEN, len - NLMSG_HDRLEN);
		_hex((uint8_t *) hdr + NLMSG_HDRLEN, len - NLMSG_HDRLEN);
	}
}
示例#6
0
void hex(struct pkt_buff *pkt)
{
	size_t len = pkt_len(pkt);

	if (!len)
		return;

	_hex(pkt_pull(pkt, len), len);
	tprintf("\n");
}
示例#7
0
static inline char *_toNumber(char *str,long long value,_bool sign,
        HexBase base,int size,int style,int mask){
    char signString = '+';
    const char *dig = _lowerDigits;
    int tmp[64];       //缓存转换后的值.还不是ASCII 
    int length = 0;

    if(style & STYLE_LARGE) dig = _upperDigits;
    if(style & STYLE_LEFT) style &= (~STYLE_ZEROPAD); //左对齐就不能使用0填充
    //如果不是10进制,则都按无符号处理 ,并且无正负符号显示
    //如果是10进制,则去除前缀属性
    if(DECIMAL != base){
        sign = _false;
        style &= ~STYLE_SIGN;
    } else {
        style &= ~STYLE_SPECIAL;
    }

    if(style & STYLE_SPECIAL){
        if(HEX == base) size -= 2;
        else if(OCTAL == base) size -= 1;
    }

    //如果是有符号数,却小于0,则取其补码,并设置符号标志,非16进制在前面已经去除
    //符号,所以不会受影响
    if((_true == sign) && ((long long)value) < 0){
            style |= STYLE_SIGN;
            value = ~value + 1;
            signString = '-';
    }

    value &= mask;
    if(style & STYLE_SIGN) size --;

    switch(base){
        case OCTAL:length = _octal(tmp,value);break;
        case DECIMAL:length = _decimal(tmp,value);break;
        case HEX:length = _hex(tmp,value);break;
    } 
    size -= length;

    if(!(style & (STYLE_ZEROPAD|STYLE_LEFT))) while(size-- > 0) *str++ = ' ';
    if(style & STYLE_SIGN) *str++ = signString;
    if(style & STYLE_SPECIAL){
        *str++ = '0';
        if(HEX == base) *str++ = dig[0x10];
    }
    if(style & STYLE_ZEROPAD) while(size-- > 0) *str++ = '0';
    while(length-- > 0) *str++ = dig[tmp[length]];
    if(style & STYLE_LEFT) while(size-- > 0) *str++ = ' ';

    return str;
}
示例#8
0
TokenT *_hex(TokenizerT *tk, int isFirst) {
    nextChar(tk);
    if(isxdigit(tk->inputIter[0])) {
        return _hex(tk, 0);
    } else {
        if(isFirst) {
            return _invalid(tk);
        } else {
            return makeToken(tk, "hexadecimal integer");
        }
    }
}
示例#9
0
void hex_ascii(struct pkt_buff *pkt)
{
	size_t   len = pkt_len(pkt);
	uint8_t *ptr = pkt_pull(pkt, len);

	if (len) {
		_ascii(ptr, len);
		_hex(ptr, len);
	}

	tprintf("\n");
}
示例#10
0
/*
 * Handle being given a zero as the first char in a new token.
 */
TokenT *_zero(TokenizerT *tk) {
    nextChar(tk);
    if(isOctal(tk->inputIter[0])) {
        return _octal(tk);
    } else if(tk->inputIter[0] == 'x' || (tk->inputIter[0]) == 'X') {
        return _hex(tk, 1);
    } else if(tk->inputIter[0] == '.') {
        return _float(tk, 1);
    } else {
        return makeToken(tk, "zero integer");
    }
}
示例#11
0
void SystemBubble::_SendAddBalls( SystemEntity* to_who )
{
	if( m_entities.empty() )
    {
		_log( DESTINY__TRACE, "Add Balls: Nothing to send." );
		return;
	}

    Buffer* destinyBuffer = new Buffer;

    Destiny::AddBall_header head;
	head.packet_type = 0;
	head.sequence = DestinyManager::GetStamp();

    destinyBuffer->Append( head );

    DoDestiny_AddBalls addballs;
    addballs.slims = new PyList;

    std::map<uint32, SystemEntity*>::const_iterator cur, end;
	cur = m_entities.begin();
	end = m_entities.end();
	for(; cur != end; ++cur)
    {
		if( cur->second->IsVisibleSystemWide() )
			continue;	//it is already in their destiny state

        //damageState
		addballs.damages[ cur->second->GetID() ] = cur->second->MakeDamageState();
		//slim item
		addballs.slims->AddItem( new PyObject( "foo.SlimItem", cur->second->MakeSlimItem() ) );
		//append the destiny binary data...
		cur->second->EncodeDestiny( *destinyBuffer );
	}

    addballs.destiny_binary = new PyBuffer( &destinyBuffer );
    SafeDelete( destinyBuffer );

    _log( DESTINY__TRACE, "Add Balls:" );
    addballs.Dump( DESTINY__TRACE, "    " );
    _log( DESTINY__TRACE, "    Ball Binary:" );
    _hex( DESTINY__TRACE, &( addballs.destiny_binary->content() )[0],
                          addballs.destiny_binary->content().size() );

    _log( DESTINY__TRACE, "    Ball Decoded:" );
    Destiny::DumpUpdate( DESTINY__TRACE, &( addballs.destiny_binary->content() )[0],
                                         addballs.destiny_binary->content().size() );

    PyTuple* t = addballs.Encode();
	to_who->QueueDestinyUpdate( &t );	//may consume, but may not.
    PySafeDecRef( t );
}
示例#12
0
文件: make_H3orbits.c 项目: etmc/cvc
void set_qid_val(double **qid_val, int ts) {

  int x1, x2, x3, nqhat=-1;
  int L = LX;
  int Lhp1 = L/2+1;
  double q[4];

  q[0] = 2. * sin( M_PI * (double)ts / (double)T );
  for(x1=0; x1<Lhp1; x1++) {
  for(x2=0; x2<=x1;  x2++) {
  for(x3=0; x3<=x2;  x3++) {
    nqhat++;
    q[1] = 2. * sin( M_PI * (double)x1 / (double)L );
    q[2] = 2. * sin( M_PI * (double)x2 / (double)L );
    q[3] = 2. * sin( M_PI * (double)x3 / (double)L );

    (qid_val)[0][nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
    (qid_val)[1][nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
    (qid_val)[2][nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
    (qid_val)[3][nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);
  }
  }
  }
}
示例#13
0
文件: string.c 项目: fy0/python_lite
pl_int_t str_escape_next(PyLiteInterpreter *I, str_writer_t *w) {
    int num;
    PyLiteStrObject *str = w->dstr;
    PyLiteStrObject *format = w->fstr;
    uint32_t format_size = format->ob_size;

    switch (format->ob_val[w->findex]) {
        case '\\':
            if (++(w->findex) >= format_size) goto _def;
            switch (format->ob_val[w->findex]) {
                case 'a': str->ob_val[w->dindex++] = 7; w->findex++; break;
                case 'b': str->ob_val[w->dindex++] = 8; w->findex++; break;
                case 'f': str->ob_val[w->dindex++] = 12; w->findex++; break;
                case 'n': str->ob_val[w->dindex++] = 10; w->findex++; break;
                case 'r': str->ob_val[w->dindex++] = 13; w->findex++; break;
                case 't': str->ob_val[w->dindex++] = 9; w->findex++; break;
                case 'v': str->ob_val[w->dindex++] = 11; break;
                case '\\': str->ob_val[w->dindex++] = '\\'; break;
                case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
					str->ob_val[w->dindex++] = _read_x_int(format->ob_val + w->findex, 8, _oct, &num, min(format_size - w->findex, 3));
                    w->findex += num;
                    break;
                case 'x':
                    w->findex++;
                    if ((format_size - w->findex >= 2) && (_ishex(format->ob_val[w->findex]) && _ishex(format->ob_val[w->findex + 1]))) {
                        str->ob_val[w->dindex++] = _hex(format->ob_val[w->findex]) * 16 + _hex(format->ob_val[w->findex + 1]);
                    } else {
                        pylt_obj_str_free(I, str);
                        // error: not hex
                        return -1;
                    }
                    w->findex += 2;
                    break;
                default:
                    if (format->ob_val[++w->findex] >= 0x80) {
                        // error
                        return -2;
                    }
                    str->ob_val[w->dindex++] = '\\';
                    str->ob_val[w->dindex++] = format->ob_val[w->findex];
                    break;
            }
			break;
        default: _def :
            str->ob_val[w->dindex++] = format->ob_val[w->findex++];
    }
    return 0;
}
示例#14
0
文件: tlexer.c 项目: fy0/tinyre
int read_hex(tre_Lexer *lex, int len, bool *p_isok) {
    const uint32_t *p = lex->s + lex->scur;
    const uint32_t *start = p;
    int count = 0;

    while (_hex(*p) != 255) {
        ++p;
        if (++count == len) break;
    }

    if (count != len) {
        p_isok = false;
        return 0;
    }

    *p_isok = true;
    return _read_x_int(start, p, 16, _hex, 0);
}
示例#15
0
void EQStream::Process(const unsigned char *buffer, const uint32 length)
{
static unsigned char newbuffer[2048];
uint32 newlength=0;
	if (EQProtocolPacket::ValidateCRC(buffer,length,Key)) {
		if (compressed) {
			newlength=EQProtocolPacket::Decompress(buffer,length,newbuffer,2048);
		} else {
			memcpy(newbuffer,buffer,length);
			newlength=length;
			if (encoded)
				EQProtocolPacket::ChatDecode(newbuffer,newlength-2,Key);
		}
		if (buffer[1]!=0x01 && buffer[1]!=0x02 && buffer[1]!=0x1d)
			newlength-=2;
		EQProtocolPacket *p = MakeProtocolPacket(newbuffer,newlength);
		ProcessPacket(p);
		delete p;
		ProcessQueue();
	} else {
		_log(NET__DEBUG, _L "Incoming packet failed checksum" __L);
		_hex(NET__NET_CREATE_HEX, buffer, length);
	}
}
示例#16
0
bool LauncherLink::Process() {
	if (!tcpc->Connected())
		return false;

	if(m_bootTimer.Check(false)) {
		//force a boot on any zone which isnt running.
		std::map<std::string, ZoneState>::iterator cur, end;
		cur = m_states.begin();
		end = m_states.end();
		for(; cur != end; ++cur) {
			if(!cur->second.up) {
				StartZone(cur->first.c_str());
			}
		}
		m_bootTimer.Disable();
	}

	ServerPacket *pack = 0;
	while((pack = tcpc->PopPacket())) {
		_hex(WORLD__ZONE_TRACE,pack->pBuffer,pack->size);
		if (!authenticated) {
			if (WorldConfig::get()->SharedKey.length() > 0) {
				if (pack->opcode == ServerOP_ZAAuth && pack->size == 16) {
					uint8 tmppass[16];
					MD5::Generate((const uchar*) WorldConfig::get()->SharedKey.c_str(), WorldConfig::get()->SharedKey.length(), tmppass);
					if (memcmp(pack->pBuffer, tmppass, 16) == 0)
						authenticated = true;
					else {
						struct in_addr in;
						in.s_addr = GetIP();
						_log(WORLD__LAUNCH_ERR, "Launcher authorization failed.");
						ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
						SendPacket(pack);
						delete pack;
						Disconnect();
						return false;
					}
				}
				else {
					struct in_addr in;
					in.s_addr = GetIP();
					_log(WORLD__LAUNCH_ERR, "Launcher authorization failed.");
					ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
					SendPacket(pack);
					delete pack;
					Disconnect();
					return false;
				}
			}
			else
			{
				_log(WORLD__LAUNCH,"**WARNING** You have not configured a world shared key in your config file. You should add a <key>STRING</key> element to your <world> element to prevent unauthroized zone access.");
				authenticated = true;
			}
			delete pack;
			continue;
		}
		switch(pack->opcode) {
		case 0:
			break;
		case ServerOP_KeepAlive: {
			// ignore this
			break;
		}
		case ServerOP_ZAAuth: {
			_log(WORLD__LAUNCH, "Got authentication from %s when they are already authenticated.", m_name.c_str());
			break;
		}
		case ServerOP_LauncherConnectInfo: {
			const LauncherConnectInfo *it = (const LauncherConnectInfo *) pack->pBuffer;
			if(HasName()) {
				_log(WORLD__LAUNCH_ERR, "Launcher '%s' received an additional connect packet with name '%s'. Ignoring.", m_name.c_str(), it->name);
				break;
			}
			m_name = it->name;

			EQLConfig *config = launcher_list.GetConfig(m_name.c_str());
			if(config == nullptr) {
				_log(WORLD__LAUNCH, "Unknown launcher '%s' connected. Disconnecting.", it->name);
				Disconnect();
				break;
			}

			_log(WORLD__LAUNCH, "Launcher Identified itself as '%s'. Loading zone list.", it->name);

			std::vector<LauncherZone> result;
			//database.GetLauncherZones(it->name, result);
			config->GetZones(result);

			std::vector<LauncherZone>::iterator cur, end;
			cur = result.begin();
			end = result.end();
			ZoneState zs;
			for(; cur != end; cur++) {
				zs.port = cur->port;
				zs.up = false;
				zs.starts = 0;
				_log(WORLD__LAUNCH_TRACE, "%s: Loaded zone '%s' on port %d", m_name.c_str(), cur->name.c_str(), zs.port);
				m_states[cur->name] = zs;
			}

			//now we add all the dynamics.
			BootDynamics(config->GetDynamicCount());

			m_bootTimer.Start();

			break;
		}
		case ServerOP_LauncherZoneStatus: {
			const LauncherZoneStatus *it = (const LauncherZoneStatus *) pack->pBuffer;
			std::map<std::string, ZoneState>::iterator res;
			res = m_states.find(it->short_name);
			if(res == m_states.end()) {
				_log(WORLD__LAUNCH_ERR, "%s: reported state for zone %s which it does not have.", m_name.c_str(), it->short_name);
				break;
			}
			_log(WORLD__LAUNCH, "%s: %s reported state %s (%d starts)", m_name.c_str(), it->short_name, it->running?"STARTED":"STOPPED", it->start_count);
			res->second.up = it->running;
			res->second.starts = it->start_count;
			break;
		}
		default:
		{
			_log(WORLD__LAUNCH_ERR, "Unknown ServerOPcode from launcher 0x%04x, size %d",pack->opcode,pack->size);
			DumpPacket(pack->pBuffer, pack->size);
			break;
		}
		}

		delete pack;
	}
	return(true);
}
示例#17
0
uint32 DumpBall(LogType into, const uint8 *data, uint32 len) {
    uint32 init_len = len;

    const Destiny::BallHeader *ballhead = (const Destiny::BallHeader *) data;
    data += sizeof(Destiny::BallHeader);
    len -= sizeof(Destiny::BallHeader);

    if(ballhead->mode > Destiny::MAX_DSTBALL) {
        _log(into, "Error: Invalid ball mode %d for ball %d", ballhead->mode, ballhead->entityID);
        return(0);
    }

    _log(into, "AddBall: entity=%d, mode=%s (%d) subtype=%d",
        ballhead->entityID, Destiny::DSTBALL_modeNames[ballhead->mode], ballhead->mode, ballhead->sub_type);
    _log(into, "   x=%.3f, y=%.3f, z=%.3f, radius=%.2f",
        ballhead->x, ballhead->y, ballhead->z, ballhead->radius);

    if(ballhead->mode != Destiny::DSTBALL_RIGID) {
        const Destiny::MassSector *masschunk = (const Destiny::MassSector *) data;
        data += sizeof(Destiny::MassSector);
        len -= sizeof(Destiny::MassSector);

        _log(into, "   mass=%.2f, cloak=%d, hardmonic=%f, corp=%u, alliance=0x"PRIx64,
            masschunk->mass, masschunk->cloak, masschunk->Harmonic, masschunk->corpID, masschunk->allianceID);
    }

    //this seems a little strange, but this is how it works...
    if(ballhead->sub_type & 0x1) {
        const Destiny::ShipSector *shipchunk = (const Destiny::ShipSector *) data;
        data += sizeof(Destiny::ShipSector);
        len -= sizeof(Destiny::ShipSector);

        _log(into, "   maxSpeed=%.2f, V=(%.3f, %.3f, %.3f) PS=%.4f, SF=%.3f",
            shipchunk->max_speed,
            shipchunk->velocity_x, shipchunk->velocity_y, shipchunk->velocity_z,
            shipchunk->agility,
            shipchunk->speed_fraction);
    }

    _log(into, "   %s:", Destiny::DSTBALL_modeNames[ballhead->mode]);
    switch(ballhead->mode) {
    case Destiny::DSTBALL_GOTO: {
        const Destiny::DSTBALL_GOTO_Struct *b = (const Destiny::DSTBALL_GOTO_Struct *) data;
        data += sizeof(Destiny::DSTBALL_GOTO_Struct);
        len -= sizeof(Destiny::DSTBALL_GOTO_Struct);
        _log(into, "       formID=%d, Goto=(%.3f, %.3f, %.3f)", b->formationID,
            b->x, b->y, b->z);
    } break;
    case Destiny::DSTBALL_FOLLOW: {
        const Destiny::DSTBALL_FOLLOW_Struct *b = (const Destiny::DSTBALL_FOLLOW_Struct *) data;
        data += sizeof(Destiny::DSTBALL_FOLLOW_Struct);
        len -= sizeof(Destiny::DSTBALL_FOLLOW_Struct);
        _log(into, "       formID=%d, followID=%u, distance=%.1f", b->formationID,
            b->followID, b->followRange);
    } break;
    case Destiny::DSTBALL_STOP: {
        const Destiny::DSTBALL_STOP_Struct *b = (const Destiny::DSTBALL_STOP_Struct *) data;
        data += sizeof(Destiny::DSTBALL_STOP_Struct);
        len -= sizeof(Destiny::DSTBALL_STOP_Struct);
        _log(into, "       formID=%d ", b->formationID);
    } break;
    case Destiny::DSTBALL_WARP: {
        const Destiny::DSTBALL_WARP_Struct *b = (const Destiny::DSTBALL_WARP_Struct *) data;
        data += sizeof(Destiny::DSTBALL_WARP_Struct);
        len -= sizeof(Destiny::DSTBALL_WARP_Struct);
        _log(into, "       formID=%d, To=(%.3f, %.3f, %.3f) effectStamp=%u", b->formationID,
            b->unknown_x, b->unknown_y, b->unknown_z, b->effectStamp);
        _log(into, "       followRange=%.3f, followID=%u, ownerID=%u",
            b->followRange, b->followID, b->ownerID);
    } break;
    case Destiny::DSTBALL_ORBIT: {
        const Destiny::DSTBALL_ORBIT_Struct *b = (const Destiny::DSTBALL_ORBIT_Struct *) data;
        data += sizeof(Destiny::DSTBALL_ORBIT_Struct);
        len -= sizeof(Destiny::DSTBALL_ORBIT_Struct);
        _log(into, "       formID=%d, orbitID=%u, distance=%.1f", b->formationID,
            b->followID, b->followRange);
    } break;
    case Destiny::DSTBALL_MISSILE: {
        const Destiny::DSTBALL_MISSILE_Struct *b = (const Destiny::DSTBALL_MISSILE_Struct *) data;
        data += sizeof(Destiny::DSTBALL_MISSILE_Struct);
        len -= sizeof(Destiny::DSTBALL_MISSILE_Struct);
        _log(into, "       formID=%d, target=%u, followRange?=%.1f, ownerID=%u, effectStamp=%u", b->formationID,
            b->followID, b->followRange, b->ownerID, b->effectStamp);
        _log(into, "       u=(%.3f, %.3f, %.3f)",
            b->x, b->y, b->z);
    } break;
    case Destiny::DSTBALL_MUSHROOM: {
        const Destiny::DSTBALL_MUSHROOM_Struct *b = (const Destiny::DSTBALL_MUSHROOM_Struct *) data;
        data += sizeof(Destiny::DSTBALL_MUSHROOM_Struct);
        len -= sizeof(Destiny::DSTBALL_MUSHROOM_Struct);
        _log(into, "       formID=%d, distance=%.3f, u125=%.3f, effectStamp=%u, ownerID=%u", b->formationID,
            b->followRange, b->unknown125, b->effectStamp, b->ownerID);
    } break;
    case Destiny::DSTBALL_BOID: {
        _log(into, "       NOT ALLOWED IN STREAM!");
        return(0);
    } break;
    case Destiny::DSTBALL_TROLL: {
        const Destiny::DSTBALL_TROLL_Struct *b = (const Destiny::DSTBALL_TROLL_Struct *) data;
        data += sizeof(Destiny::DSTBALL_TROLL_Struct);
        len -= sizeof(Destiny::DSTBALL_TROLL_Struct);
        _log(into, "       formID=%d, effectStamp=%u", b->formationID,
            b->effectStamp);
    } break;
    case Destiny::DSTBALL_MINIBALL: {
        _log(into, "       NOT ALLOWED IN STREAM!");
        return(0);
    } break;
    case Destiny::DSTBALL_FIELD: {
        const Destiny::DSTBALL_FIELD_Struct *b = (const Destiny::DSTBALL_FIELD_Struct *) data;
        data += sizeof(Destiny::DSTBALL_FIELD_Struct);
        len -= sizeof(Destiny::DSTBALL_FIELD_Struct);
        _log(into, "       formID=%d ", b->formationID);
    } break;
    case Destiny::DSTBALL_RIGID: {
        const Destiny::DSTBALL_RIGID_Struct *b = (const Destiny::DSTBALL_RIGID_Struct *) data;
        data += sizeof(Destiny::DSTBALL_RIGID_Struct);
        len -= sizeof(Destiny::DSTBALL_RIGID_Struct);
        _log(into, "       formID=%d ", b->formationID);
    } break;
    case Destiny::DSTBALL_FORMATION: {
        const Destiny::DSTBALL_FORMATION_Struct *b = (const Destiny::DSTBALL_FORMATION_Struct *) data;
        data += sizeof(Destiny::DSTBALL_FORMATION_Struct);
        len -= sizeof(Destiny::DSTBALL_FORMATION_Struct);
        _log(into, "       formID=%d, followID=%u, followRange=%.3f, effectStamp=%u", b->formationID,
            b->followID, b->followRange, b->effectStamp);
    } break;
    default:
        _log(into, "Error: Unknown ball mode %d!", ballhead->mode);
        _hex(into, data-sizeof(Destiny::BallHeader), (len>128)?128:(len+sizeof(Destiny::BallHeader)));
        return(0);
    }

    //not right:
    if( ( ballhead->sub_type == 64 ) || ( ballhead->sub_type == 66 ) )
    {
        const Destiny::MiniBallList* mbl = (const Destiny::MiniBallList*)data;
        data += sizeof( Destiny::MiniBallList );
        len -= sizeof( Destiny::MiniBallList );

        if( 0 < mbl->count )
        {
            _log( into, "    MiniBall Count: %d", mbl->count );

            for( uint16 r = 0; r < mbl->count; ++r )
            {
                const Destiny::MiniBall* mini = (const Destiny::MiniBall*)data;
                data += sizeof( Destiny::MiniBall );
                len -= sizeof( Destiny::MiniBall );

                _log( into, "        [%d] pos (%.3f, %.3f, %.3f) radius %.2f",
                      r, mini->x, mini->y, mini->z, mini->radius );
            }
        }
    }

    const Destiny::NameStruct *name = (const Destiny::NameStruct *) data;
    data += sizeof(Destiny::NameStruct);
    len -= sizeof(Destiny::NameStruct);
    if(name->name_len > 0) {
        _log(into, "   Name: len=%u", name->name_len);
        _log(into, "     %.*ls", name->name_len, name->name);

        data += name->name_len*sizeof(uint16);
        len  -= name->name_len*sizeof(uint16);
    }

    if(len > init_len) {
        _log(into, "ERROR: Consumed more bytes than given: had %d, used %d", init_len, len);
        return(init_len);
    }
    return(init_len - len);
}
示例#18
0
bool ZoneServer::Process() {
	if (!tcpc->Connected())
		return false;
	if(ls_zboot.Check()){
		LSBootUpdate(GetZoneID(), true);
		ls_zboot.Disable();
	}
	ServerPacket *pack = 0;
	while((pack = tcpc->PopPacket())) {
		_hex(WORLD__ZONE_TRACE,pack->pBuffer,pack->size);
		if (!authenticated) {
			if (WorldConfig::get()->SharedKey.length() > 0) {
				if (pack->opcode == ServerOP_ZAAuth && pack->size == 16) {
					uint8 tmppass[16];
					MD5::Generate((const uchar*) WorldConfig::get()->SharedKey.c_str(), WorldConfig::get()->SharedKey.length(), tmppass);
					if (memcmp(pack->pBuffer, tmppass, 16) == 0)
						authenticated = true;
					else {
						struct in_addr  in;
						in.s_addr = GetIP();
						zlog(WORLD__ZONE_ERR,"Zone authorization failed.");
						ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
						SendPacket(pack);
						delete pack;
						Disconnect();
						return false;
					}
				}
				else {
					struct in_addr  in;
					in.s_addr = GetIP();
					zlog(WORLD__ZONE_ERR,"Zone authorization failed.");
					ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
					SendPacket(pack);
					delete pack;
					Disconnect();
					return false;
				}
			}
			else
			{
				_log(WORLD__ZONE,"**WARNING** You have not configured a world shared key in your config file. You should add a <key>STRING</key> element to your <world> element to prevent unauthroized zone access.");
				authenticated = true;
			}
		}
		switch(pack->opcode) {
		case 0:
			break;
		case ServerOP_KeepAlive: {
			// ignore this
			break;
		}
		case ServerOP_ZAAuth: {
			break;
		}
		case ServerOP_LSZoneBoot:{
			if(pack->size==sizeof(ZoneBoot_Struct)){
				ZoneBoot_Struct* zbs= (ZoneBoot_Struct*)pack->pBuffer;
				SetCompile(zbs->compile_time);
			}
			break;
		}
		case ServerOP_GroupInvite: {
			if(pack->size != sizeof(GroupInvite_Struct))
				break;

			GroupInvite_Struct* gis = (GroupInvite_Struct*) pack->pBuffer;

			client_list.SendPacket(gis->invitee_name, pack);
			break;
		}
		case ServerOP_GroupFollow: {
			if(pack->size != sizeof(ServerGroupFollow_Struct))
				break;

			ServerGroupFollow_Struct *sgfs = (ServerGroupFollow_Struct *) pack->pBuffer;

			client_list.SendPacket(sgfs->gf.name1, pack);
			break;
		}
		case ServerOP_GroupFollowAck: {
			if(pack->size != sizeof(ServerGroupFollowAck_Struct))
				break;

			ServerGroupFollowAck_Struct *sgfas = (ServerGroupFollowAck_Struct *) pack->pBuffer;

			client_list.SendPacket(sgfas->Name, pack);
			break;
		}
		case ServerOP_GroupCancelInvite: {
			if(pack->size != sizeof(GroupCancel_Struct))
				break;

			GroupCancel_Struct *gcs = (GroupCancel_Struct *) pack->pBuffer;

			client_list.SendPacket(gcs->name1, pack);
			break;
		}
		case ServerOP_GroupIDReq: {
			SendGroupIDs();
			break;
		}
		case ServerOP_GroupLeave: {
			if(pack->size != sizeof(ServerGroupLeave_Struct))
				break;
			zoneserver_list.SendPacket(pack); //bounce it to all zones
			break;
		}

		case ServerOP_GroupJoin: {
			if(pack->size != sizeof(ServerGroupJoin_Struct))
				break;
			zoneserver_list.SendPacket(pack); //bounce it to all zones
			break;
		}

		case ServerOP_ForceGroupUpdate: {
			if(pack->size != sizeof(ServerForceGroupUpdate_Struct))
				break;
			zoneserver_list.SendPacket(pack); //bounce it to all zones
			break;
		}

		case ServerOP_OOZGroupMessage: {
			zoneserver_list.SendPacket(pack); //bounce it to all zones
			break;
		}

		case ServerOP_DisbandGroup: {
			if(pack->size != sizeof(ServerDisbandGroup_Struct))
				break;
			zoneserver_list.SendPacket(pack); //bounce it to all zones
			break;
		}

		case ServerOP_RaidAdd:{
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidRemove: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidDisband: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidLockFlag: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidChangeGroup: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_UpdateGroup: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidGroupDisband: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidGroupAdd: {
			if(pack->size != sizeof(ServerRaidGroupAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidGroupRemove: {
			if(pack->size != sizeof(ServerRaidGroupAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidGroupSay: {
			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidSay: {
			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidGroupLeader: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_RaidLeader: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_DetailsChange: {
			if(pack->size != sizeof(ServerRaidGeneralAction_Struct))
				break;

			zoneserver_list.SendPacket(pack);
			break;
		}

		case ServerOP_SpawnCondition: {
			if(pack->size != sizeof(ServerSpawnCondition_Struct))
				break;
			//bounce the packet to the correct zone server, if its up
			ServerSpawnCondition_Struct* ssc = (ServerSpawnCondition_Struct*)pack->pBuffer;
			zoneserver_list.SendPacket(ssc->zoneID, ssc->instanceID, pack);
			break;
		}
		case ServerOP_SpawnEvent: {
			if(pack->size != sizeof(ServerSpawnEvent_Struct))
				break;
			//bounce the packet to the correct zone server, if its up
			ServerSpawnEvent_Struct* sse = (ServerSpawnEvent_Struct*)pack->pBuffer;
			zoneserver_list.SendPacket(sse->zoneID, 0, pack);
			break;
		}
		case ServerOP_ChannelMessage: {
			ServerChannelMessage_Struct* scm = (ServerChannelMessage_Struct*) pack->pBuffer;
			if(scm->chan_num == 20)
			{
				UCSLink.SendMessage(scm->from, scm->message);
				break;
			}
			if (scm->chan_num == 7 || scm->chan_num == 14) {
				if (scm->deliverto[0] == '*') {
					Console* con = 0;
					con = console_list.FindByAccountName(&scm->deliverto[1]);
					if (((!con) || (!con->SendChannelMessage(scm))) && (!scm->noreply))
						zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "You told %s, '%s is not online at this time'", scm->to, scm->to);
					break;
				}
				ClientListEntry* cle = client_list.FindCharacter(scm->deliverto);
				if (cle == 0 || cle->Online() < CLE_Status_Zoning || (cle->TellsOff() && ((cle->Anon() == 1 && scm->fromadmin < cle->Admin()) || scm->fromadmin < 80))) {
					if (!scm->noreply)
						zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "You told %s, '%s is not online at this time'", scm->to, scm->to);
				}
				else if (cle->Online() == CLE_Status_Zoning) {
					if (!scm->noreply) {
						char errbuf[MYSQL_ERRMSG_SIZE];
						char *query = 0;
						MYSQL_RES *result;
						//MYSQL_ROW row;   Trumpcard - commenting.  Currently unused.
						time_t rawtime;
						struct tm * timeinfo;
						time ( &rawtime );
						timeinfo = localtime ( &rawtime );
						char *telldate=asctime(timeinfo);
						if (database.RunQuery(query, MakeAnyLenString(&query, "SELECT name from character_ where name='%s'",scm->deliverto), errbuf, &result)) {
							safe_delete(query);
							if (result!=0) {
								if (database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO tellque (Date,Receiver,Sender,Message) values('%s','%s','%s','%s')",telldate,scm->deliverto,scm->from,scm->message), errbuf, &result))
									zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "Your message has been added to the %s's que.", scm->to);
								else
									zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "You told %s, '%s is not online at this time'", scm->to, scm->to);
								safe_delete(query);
							}
							else
								zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "You told %s, '%s is not online at this time'", scm->to, scm->to);
							mysql_free_result(result);
						}
						else
							safe_delete(query);
					}
				//		zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "You told %s, '%s is not online at this time'", scm->to, scm->to);
				}
				else if (cle->Server() == 0) {
					if (!scm->noreply)
						zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "You told %s, '%s is not contactable at this time'", scm->to, scm->to);
				}
				else
					cle->Server()->SendPacket(pack);
			}
			else {
				if (scm->chan_num == 5 || scm->chan_num == 6 || scm->chan_num == 11) {
					console_list.SendChannelMessage(scm);
				}
				zoneserver_list.SendPacket(pack);
			}
			break;
		}
		case ServerOP_EmoteMessage: {
			ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*) pack->pBuffer;
			zoneserver_list.SendEmoteMessageRaw(sem->to, sem->guilddbid, sem->minstatus, sem->type, sem->message);
			break;
		}
		case ServerOP_VoiceMacro: {

			ServerVoiceMacro_Struct* svm = (ServerVoiceMacro_Struct*) pack->pBuffer;
			
			if(svm->Type == VoiceMacroTell) {

				ClientListEntry* cle = client_list.FindCharacter(svm->To);

				if (!cle || (cle->Online() < CLE_Status_Zoning) || !cle->Server())  {

					zoneserver_list.SendEmoteMessage(svm->From, 0, 0, 0, "'%s is not online at this time'", svm->To);

					break;
				}

				cle->Server()->SendPacket(pack);
			}
			else
				zoneserver_list.SendPacket(pack);

			break;
		}

		case ServerOP_RezzPlayerAccept: {
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_RezzPlayer: {

			RezzPlayer_Struct* sRezz = (RezzPlayer_Struct*) pack->pBuffer;
			if (zoneserver_list.SendPacket(pack)){
				zlog(WORLD__ZONE,"Sent Rez packet for %s",sRezz->rez.your_name);
			}
			else {
				zlog(WORLD__ZONE,"Could not send Rez packet for %s",sRezz->rez.your_name);
			}
			break;
		}
		case ServerOP_RezzPlayerReject:
		{
			char *Recipient = (char *)pack->pBuffer;
			client_list.SendPacket(Recipient, pack);
			break;
		}

		case ServerOP_MultiLineMsg: {
			ServerMultiLineMsg_Struct* mlm = (ServerMultiLineMsg_Struct*) pack->pBuffer;
			client_list.SendPacket(mlm->to, pack);
			break;
		}
		case ServerOP_SetZone: {
			if(pack->size != sizeof(SetZone_Struct))
				break;

			SetZone_Struct* szs = (SetZone_Struct*) pack->pBuffer;	
			if (szs->zoneid != 0) {
				if(database.GetZoneName(szs->zoneid))
					SetZone(szs->zoneid, szs->instanceid, szs->staticzone);
				else
					SetZone(0);
			}
			else
				SetZone(0);

			break;
		}
		case ServerOP_SetConnectInfo: {
			if (pack->size != sizeof(ServerConnectInfo))
					break;
			ServerConnectInfo* sci = (ServerConnectInfo*) pack->pBuffer;

			if (!sci->port) {
				clientport=zoneserver_list.GetAvailableZonePort();

				ServerPacket p(ServerOP_SetConnectInfo, sizeof(ServerConnectInfo));
				memset(p.pBuffer,0,sizeof(ServerConnectInfo));
				ServerConnectInfo* sci = (ServerConnectInfo*) p.pBuffer;
				sci->port = clientport;
				SendPacket(&p);
				zlog(WORLD__ZONE,"Auto zone port configuration.  Telling zone to use port %d",clientport);
			} else {
				clientport=sci->port;
				zlog(WORLD__ZONE,"Zone specified port %d, must be a previously allocated zone reconnecting.",clientport);
			}

		}
		case ServerOP_SetLaunchName: {
			if(pack->size != sizeof(LaunchName_Struct))
				break;
			const LaunchName_Struct* ln = (const LaunchName_Struct*)pack->pBuffer;
			launcher_name = ln->launcher_name;
			launched_name = ln->zone_name;
			zlog(WORLD__ZONE, "Zone started with name %s by launcher %s", launched_name.c_str(), launcher_name.c_str());
			break;
		}
		case ServerOP_ShutdownAll: {
			if(pack->size==0){
				zoneserver_list.SendPacket(pack);
				zoneserver_list.Process();
				CatchSignal(2);
			}
			else{
				WorldShutDown_Struct* wsd=(WorldShutDown_Struct*)pack->pBuffer;
				if(wsd->time==0 && wsd->interval==0 && zoneserver_list.shutdowntimer->Enabled()){
					zoneserver_list.shutdowntimer->Disable();
					zoneserver_list.reminder->Disable();
				}
				else{
					zoneserver_list.shutdowntimer->SetTimer(wsd->time);
					zoneserver_list.reminder->SetTimer(wsd->interval-1000);
					zoneserver_list.reminder->SetAtTrigger(wsd->interval);
					zoneserver_list.shutdowntimer->Start();
					zoneserver_list.reminder->Start();
				}
			}
			break;
		}
		case ServerOP_ZoneShutdown: {
			ServerZoneStateChange_struct* s = (ServerZoneStateChange_struct *) pack->pBuffer;
			ZoneServer* zs = 0;
			if (s->ZoneServerID != 0)
				zs = zoneserver_list.FindByID(s->ZoneServerID);
			else if (s->zoneid != 0)
				zs = zoneserver_list.FindByName(database.GetZoneName(s->zoneid));
			else
				zoneserver_list.SendEmoteMessage(s->adminname, 0, 0, 0, "Error: SOP_ZoneShutdown: neither ID nor name specified");

			if (zs == 0)
				zoneserver_list.SendEmoteMessage(s->adminname, 0, 0, 0, "Error: SOP_ZoneShutdown: zoneserver not found");
			else
				zs->SendPacket(pack);
			break;
		}
		case ServerOP_ZoneBootup: {
			ServerZoneStateChange_struct* s = (ServerZoneStateChange_struct *) pack->pBuffer;
			zoneserver_list.SOPZoneBootup(s->adminname, s->ZoneServerID, database.GetZoneName(s->zoneid), s->makestatic);
			break;
		}
		case ServerOP_ZoneStatus: {
			if (pack->size >= 1)
				zoneserver_list.SendZoneStatus((char *) &pack->pBuffer[1], (uint8) pack->pBuffer[0], this);
			break;

		}
		case ServerOP_AcceptWorldEntrance: {
			if(pack->size != sizeof(WorldToZone_Struct))
				break;

			WorldToZone_Struct* wtz = (WorldToZone_Struct*) pack->pBuffer;
			Client* client = 0;
			client = client_list.FindByAccountID(wtz->account_id);
			if(client != 0)
				client->Clearance(wtz->response);
		}
		case ServerOP_ZoneToZoneRequest: {
		//
		// solar: ZoneChange is received by the zone the player is in, then the
		// zone sends a ZTZ which ends up here.  This code then find the target
		// (ingress point) and boots it if needed, then sends the ZTZ to it.
		// The ingress server will decide wether the player can enter, then will
		// send back the ZTZ to here.  This packet is passed back to the egress
		// server, which will send a ZoneChange response back to the client
		// which can be an error, or a success, in which case the client will
		// disconnect, and their zone location will be saved when ~Client is
		// called, so it will be available when they ask to zone.
		//

			
			if(pack->size != sizeof(ZoneToZone_Struct))
				break;
			ZoneToZone_Struct* ztz = (ZoneToZone_Struct*) pack->pBuffer;
			ClientListEntry* client = NULL;
			if(WorldConfig::get()->UpdateStats)
				client = client_list.FindCharacter(ztz->name);

			zlog(WORLD__ZONE,"ZoneToZone request for %s current zone %d req zone %d\n",
				ztz->name, ztz->current_zone_id, ztz->requested_zone_id);

			if(GetZoneID() == ztz->current_zone_id && GetInstanceID() == ztz->current_instance_id)	// this is a request from the egress zone
			{
				zlog(WORLD__ZONE,"Processing ZTZ for egress from zone for client %s\n", ztz->name);

				if
				(
					ztz->admin < 80 &&
					ztz->ignorerestrictions < 2 &&
					zoneserver_list.IsZoneLocked(ztz->requested_zone_id)
				)
				{
					ztz->response = 0;
					SendPacket(pack);
					break;
				}

				ZoneServer *ingress_server = NULL;
				if(ztz->requested_instance_id > 0)
				{
					ingress_server = zoneserver_list.FindByInstanceID(ztz->requested_instance_id);
				}
				else
				{
					ingress_server = zoneserver_list.FindByZoneID(ztz->requested_zone_id);

				}

				if(ingress_server)	// found a zone already running
				{
					_log(WORLD__ZONE,"Found a zone already booted for %s\n", ztz->name);
					ztz->response = 1;
				}
				else	// need to boot one
				{
					int server_id;
					if ((server_id = zoneserver_list.TriggerBootup(ztz->requested_zone_id, ztz->requested_instance_id))){
						_log(WORLD__ZONE,"Successfully booted a zone for %s\n", ztz->name);
						// bootup successful, ready to rock
						ztz->response = 1;
						ingress_server = zoneserver_list.FindByID(server_id);
					}
					else
					{
						_log(WORLD__ZONE_ERR,"FAILED to boot a zone for %s\n", ztz->name);
						// bootup failed, send back error code 0
						ztz->response = 0;
					}
				}
				if(ztz->response!=0 && client)
					client->LSZoneChange(ztz);
				SendPacket(pack);	// send back to egress server
				if(ingress_server)	// if we couldn't boot one, this is 0
				{
					ingress_server->SendPacket(pack);	// inform target server
				}
			}
			else	// this is response from the ingress server, route it back to the egress server
			{
				zlog(WORLD__ZONE,"Processing ZTZ for ingress to zone for client %s\n", ztz->name);
				ZoneServer *egress_server = NULL;
				if(ztz->current_instance_id > 0)
				{
					egress_server = zoneserver_list.FindByInstanceID(ztz->current_instance_id);
				}
				else
				{
					egress_server = zoneserver_list.FindByZoneID(ztz->current_zone_id);
				}

				if(egress_server)
				{
					egress_server->SendPacket(pack);
				}
			}

			break;
		}
		case ServerOP_ClientList: {
			if (pack->size != sizeof(ServerClientList_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_ClientList. Got: %d, Expected: %d",pack->size,sizeof(ServerClientList_Struct));
				break;
			}
			client_list.ClientUpdate(this, (ServerClientList_Struct*) pack->pBuffer);
			break;
		}
		case ServerOP_ClientListKA: {
			ServerClientListKeepAlive_Struct* sclka = (ServerClientListKeepAlive_Struct*) pack->pBuffer;
			if (pack->size < 4 || pack->size != 4 + (4 * sclka->numupdates)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_ClientListKA. Got: %d, Expected: %d",pack->size, (4 + (4 * sclka->numupdates)));
				break;
			}
			client_list.CLEKeepAlive(sclka->numupdates, sclka->wid);
			break;
		}
		case ServerOP_Who: {
			ServerWhoAll_Struct* whoall = (ServerWhoAll_Struct*) pack->pBuffer;
			Who_All_Struct* whom = new Who_All_Struct;
			memset(whom,0,sizeof(Who_All_Struct));
			whom->gmlookup = whoall->gmlookup;
			whom->lvllow = whoall->lvllow;
			whom->lvlhigh = whoall->lvlhigh;
			whom->wclass = whoall->wclass;
			whom->wrace = whoall->wrace;
			strcpy(whom->whom,whoall->whom);
			client_list.SendWhoAll(whoall->fromid,whoall->from, whoall->admin, whom, this);
			delete whom;
			break;
		}
		case ServerOP_RequestOnlineGuildMembers:
		{
			ServerRequestOnlineGuildMembers_Struct *srogms = (ServerRequestOnlineGuildMembers_Struct*) pack->pBuffer;
			zlog(GUILDS__IN_PACKETS, "ServerOP_RequestOnlineGuildMembers Recieved. FromID=%i GuildID=%i", srogms->FromID, srogms->GuildID);	
			client_list.SendOnlineGuildMembers(srogms->FromID, srogms->GuildID);
			break;
		}
		case ServerOP_ClientVersionSummary:
		{
			ServerRequestClientVersionSummary_Struct *srcvss = (ServerRequestClientVersionSummary_Struct*) pack->pBuffer;
			client_list.SendClientVersionSummary(srcvss->Name);
			break;
		}
		case ServerOP_ReloadRules:
		{
			zoneserver_list.SendPacket(pack);
			rules->LoadRules(&database, "default");
			break;
		}
		case ServerOP_ReloadRulesWorld:
		{
			rules->LoadRules(&database, "default");
			break;
		}
		case ServerOP_CameraShake:
		{
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_FriendsWho: {
			ServerFriendsWho_Struct* FriendsWho = (ServerFriendsWho_Struct*) pack->pBuffer;
			client_list.SendFriendsWho(FriendsWho, this);
			break;
		}
		case ServerOP_LFGMatches: {
			ServerLFGMatchesRequest_Struct* smrs = (ServerLFGMatchesRequest_Struct*) pack->pBuffer;
			client_list.SendLFGMatches(smrs);
			break;
		}
		case ServerOP_LFPMatches: {
			ServerLFPMatchesRequest_Struct* smrs = (ServerLFPMatchesRequest_Struct*) pack->pBuffer;
			LFPGroupList.SendLFPMatches(smrs);
			break;
		}
		case ServerOP_LFPUpdate: {
			ServerLFPUpdate_Struct* sus = (ServerLFPUpdate_Struct*) pack->pBuffer;	
			if(sus->Action) 
				LFPGroupList.UpdateGroup(sus);
			else
				LFPGroupList.RemoveGroup(sus);
			break;
		}
		case ServerOP_ZonePlayer: {
			//ServerZonePlayer_Struct* szp = (ServerZonePlayer_Struct*) pack->pBuffer;
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_KickPlayer: {
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_KillPlayer: {
			zoneserver_list.SendPacket(pack);
			break;
		}
		
		case ServerOP_GuildRankUpdate:
		{
			zoneserver_list.SendPacket(pack);
			break;
		}
		//these opcodes get processed by the guild manager.
		case ServerOP_RefreshGuild:
		case ServerOP_DeleteGuild:
		case ServerOP_GuildCharRefresh:
		case ServerOP_GuildMemberUpdate: {
			guild_mgr.ProcessZonePacket(pack);
			break;
		}
		
		case ServerOP_FlagUpdate: {
			ClientListEntry* cle = client_list.FindCLEByAccountID(*((uint32*) pack->pBuffer));
			if (cle)
				cle->SetAdmin(*((int16*) &pack->pBuffer[4]));
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_GMGoto: {
			if (pack->size != sizeof(ServerGMGoto_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_GMGoto. Got: %d, Expected: %d",pack->size,sizeof(ServerGMGoto_Struct));
				break;
			}
			ServerGMGoto_Struct* gmg = (ServerGMGoto_Struct*) pack->pBuffer;
			ClientListEntry* cle = client_list.FindCharacter(gmg->gotoname);
			if (cle != 0) {
				if (cle->Server() == 0)
					this->SendEmoteMessage(gmg->myname, 0, 0, 13, "Error: Cannot identify %s's zoneserver.", gmg->gotoname);
				else if (cle->Anon() == 1 && cle->Admin() > gmg->admin) // no snooping for anon GMs
					this->SendEmoteMessage(gmg->myname, 0, 0, 13, "Error: %s not found", gmg->gotoname);
				else
					cle->Server()->SendPacket(pack);
			}
			else {
				this->SendEmoteMessage(gmg->myname, 0, 0, 13, "Error: %s not found", gmg->gotoname);
			}
			break;
		}
		case ServerOP_Lock: {
			if (pack->size != sizeof(ServerLock_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_Lock. Got: %d, Expected: %d",pack->size,sizeof(ServerLock_Struct));
				break;
			}
			ServerLock_Struct* slock = (ServerLock_Struct*) pack->pBuffer;
  			if (slock->mode >= 1) 
				WorldConfig::LockWorld();
			else
				WorldConfig::UnlockWorld();
			if (loginserverlist.Connected()) {
				loginserverlist.SendStatus();
				if (slock->mode >= 1)
					this->SendEmoteMessage(slock->myname, 0, 0, 13, "World locked");
				else
					this->SendEmoteMessage(slock->myname, 0, 0, 13, "World unlocked");
			}
			else {
				if (slock->mode >= 1)
					this->SendEmoteMessage(slock->myname, 0, 0, 13, "World locked, but login server not connected.");
				else 
					this->SendEmoteMessage(slock->myname, 0, 0, 13, "World unlocked, but login server not conencted.");
			}
			break;
							}
		case ServerOP_Motd: {
			if (pack->size != sizeof(ServerMotd_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_Motd. Got: %d, Expected: %d",pack->size,sizeof(ServerMotd_Struct));
				break;
			}
			ServerMotd_Struct* smotd = (ServerMotd_Struct*) pack->pBuffer;
			database.SetVariable("MOTD",smotd->motd);
			//this->SendEmoteMessage(smotd->myname, 0, 0, 13, "Updated Motd.");
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_Uptime: {
			if (pack->size != sizeof(ServerUptime_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_Uptime. Got: %d, Expected: %d",pack->size,sizeof(ServerUptime_Struct));
				break;
			}
			ServerUptime_Struct* sus = (ServerUptime_Struct*) pack->pBuffer;
			if (sus->zoneserverid == 0) {
				ZSList::ShowUpTime(this, sus->adminname);
			}
			else {
				ZoneServer* zs = zoneserver_list.FindByID(sus->zoneserverid);
				if (zs)
					zs->SendPacket(pack);
			}
			break;
							  }
		case ServerOP_Petition: {
			zoneserver_list.SendPacket(pack);
			break;
								}
		case ServerOP_GetWorldTime: {
			zlog(WORLD__ZONE,"Broadcasting a world time update");
			ServerPacket* pack = new ServerPacket;
			
			pack->opcode = ServerOP_SyncWorldTime;
			pack->size = sizeof(eqTimeOfDay);
			pack->pBuffer = new uchar[pack->size];
			memset(pack->pBuffer, 0, pack->size);
			eqTimeOfDay* tod = (eqTimeOfDay*) pack->pBuffer;
			tod->start_eqtime=zoneserver_list.worldclock.getStartEQTime();
			tod->start_realtime=zoneserver_list.worldclock.getStartRealTime();
			SendPacket(pack);
			delete pack;
			break;
									}
		case ServerOP_SetWorldTime: {
			zlog(WORLD__ZONE,"Received SetWorldTime");
			eqTimeOfDay* newtime = (eqTimeOfDay*) pack->pBuffer;
			zoneserver_list.worldclock.setEQTimeOfDay(newtime->start_eqtime, newtime->start_realtime);
			zlog(WORLD__ZONE,"New time = %d-%d-%d %d:%d (%d)\n", newtime->start_eqtime.year, newtime->start_eqtime.month, (int)newtime->start_eqtime.day, (int)newtime->start_eqtime.hour, (int)newtime->start_eqtime.minute, (int)newtime->start_realtime);
			zoneserver_list.worldclock.saveFile(WorldConfig::get()->EQTimeFile.c_str());
			zoneserver_list.SendTimeSync();
			break;
		}
		case ServerOP_IPLookup: {
			if (pack->size < sizeof(ServerGenericWorldQuery_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_IPLookup. Got: %d, Expected (at least): %d",pack->size,sizeof(ServerGenericWorldQuery_Struct));
				break;
			}
			ServerGenericWorldQuery_Struct* sgwq = (ServerGenericWorldQuery_Struct*) pack->pBuffer;
			if (pack->size == sizeof(ServerGenericWorldQuery_Struct))
				client_list.SendCLEList(sgwq->admin, sgwq->from, this);
			else
				client_list.SendCLEList(sgwq->admin, sgwq->from, this, sgwq->query);
			break;
		}
		case ServerOP_LockZone: {
			if (pack->size < sizeof(ServerLockZone_Struct)) {
				zlog(WORLD__ZONE_ERR,"Wrong size on ServerOP_LockZone. Got: %d, Expected: %d",pack->size,sizeof(ServerLockZone_Struct));
				break;
			}
			ServerLockZone_Struct* s = (ServerLockZone_Struct*) pack->pBuffer;
			switch (s->op) {
				case 0:
					zoneserver_list.ListLockedZones(s->adminname, this);
					break;
				case 1:
					if (zoneserver_list.SetLockedZone(s->zoneID, true))
						zoneserver_list.SendEmoteMessage(0, 0, 80, 15, "Zone locked: %s", database.GetZoneName(s->zoneID));
					else
						this->SendEmoteMessageRaw(s->adminname, 0, 0, 0, "Failed to change lock");
					break;
				case 2:
					if (zoneserver_list.SetLockedZone(s->zoneID, false))
						zoneserver_list.SendEmoteMessage(0, 0, 80, 15, "Zone unlocked: %s", database.GetZoneName(s->zoneID));
					else
						this->SendEmoteMessageRaw(s->adminname, 0, 0, 0, "Failed to change lock");
					break;
			}
			break;
		}
		case ServerOP_ItemStatus: {
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_OOCMute: {
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_Revoke: {
			RevokeStruct* rev = (RevokeStruct*)pack->pBuffer;
			ClientListEntry* cle = client_list.FindCharacter(rev->name);
			if (cle != 0 && cle->Server() != 0)
			{
				cle->Server()->SendPacket(pack);
			}
			break;
		}
		case ServerOP_SpawnPlayerCorpse: {
			SpawnPlayerCorpse_Struct* s = (SpawnPlayerCorpse_Struct*)pack->pBuffer;
			ZoneServer* zs = zoneserver_list.FindByZoneID(s->zone_id);
			if(zs) {
				if (zs->SendPacket(pack)) {
					zlog(WORLD__ZONE,"Sent request to spawn player corpse id %i in zone %u.",s->player_corpse_id, s->zone_id);
				}
				else {
					zlog(WORLD__ZONE_ERR,"Could not send request to spawn player corpse id %i in zone %u.",s->player_corpse_id, s->zone_id);
				}
			}
			break;
		}
	    case ServerOP_Consent: {
			// Message string id's likely to be used here are:
			// CONSENT_YOURSELF = 399
			// CONSENT_INVALID_NAME = 397
			// TARGET_NOT_FOUND = 101
			ZoneServer* zs;
			ServerOP_Consent_Struct* s = (ServerOP_Consent_Struct*)pack->pBuffer;
			ClientListEntry* cle = client_list.FindCharacter(s->grantname);
			if(cle) {
				if(cle->instance() != 0)
				{
					zs = zoneserver_list.FindByInstanceID(cle->instance());
					if(zs) {
						if(zs->SendPacket(pack)) {
							zlog(WORLD__ZONE, "Sent consent packet from player %s to player %s in zone %u.", s->ownername, s->grantname, cle->instance());
						}
						else {
							zlog(WORLD__ZONE_ERR, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent operation.", s->instance_id);
						}
					}
					else
					{
						delete pack;
						pack = new ServerPacket(ServerOP_Consent_Response, sizeof(ServerOP_Consent_Struct));
						ServerOP_Consent_Struct* scs = (ServerOP_Consent_Struct*)pack->pBuffer;
						strcpy(scs->grantname, s->grantname);
						strcpy(scs->ownername, s->ownername);
						scs->permission = s->permission;
						scs->zone_id = s->zone_id;
						scs->instance_id = s->instance_id;
						scs->message_string_id = 101;
						zs = zoneserver_list.FindByInstanceID(s->instance_id);
						if(zs) {
							if(!zs->SendPacket(pack))
								zlog(WORLD__ZONE_ERR, "Unable to send consent response back to player %s in instance %u.", s->ownername, zs->GetInstanceID());
						}
						else {
							zlog(WORLD__ZONE_ERR, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent_Response operation.", s->instance_id);
						}
					}
				}
				else
				{
					zs = zoneserver_list.FindByZoneID(cle->zone());
					if(zs) {
						if(zs->SendPacket(pack)) {
							zlog(WORLD__ZONE, "Sent consent packet from player %s to player %s in zone %u.", s->ownername, s->grantname, cle->zone());
						}
						else {
							zlog(WORLD__ZONE_ERR, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent operation.", s->zone_id);
						}
					}
					else {
						// send target not found back to requester
						delete pack;
						pack = new ServerPacket(ServerOP_Consent_Response, sizeof(ServerOP_Consent_Struct));
						ServerOP_Consent_Struct* scs = (ServerOP_Consent_Struct*)pack->pBuffer;
						strcpy(scs->grantname, s->grantname);
						strcpy(scs->ownername, s->ownername);
						scs->permission = s->permission;
						scs->zone_id = s->zone_id;
						scs->message_string_id = 101;
						zs = zoneserver_list.FindByZoneID(s->zone_id);
						if(zs) {
							if(!zs->SendPacket(pack))
								zlog(WORLD__ZONE_ERR, "Unable to send consent response back to player %s in zone %s.", s->ownername, zs->GetZoneName());
						}
						else {
							zlog(WORLD__ZONE_ERR, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id);
						}
					}
				}
			}
			else {
				// send target not found back to requester
				delete pack;
				pack = new ServerPacket(ServerOP_Consent_Response, sizeof(ServerOP_Consent_Struct));
				ServerOP_Consent_Struct* scs = (ServerOP_Consent_Struct*)pack->pBuffer;
				strcpy(scs->grantname, s->grantname);
				strcpy(scs->ownername, s->ownername);
				scs->permission = s->permission;
				scs->zone_id = s->zone_id;
				scs->message_string_id = 397;
				zs = zoneserver_list.FindByZoneID(s->zone_id);
				if(zs) {
					if(!zs->SendPacket(pack))
						zlog(WORLD__ZONE_ERR, "Unable to send consent response back to player %s in zone %s.", s->ownername, zs->GetZoneName());
				}
				else {
					zlog(WORLD__ZONE_ERR, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id);
				}
			}
			break;
		}
		case ServerOP_Consent_Response: {
			// Message string id's likely to be used here are:
			// CONSENT_YOURSELF = 399
			// CONSENT_INVALID_NAME = 397
			// TARGET_NOT_FOUND = 101
			ServerOP_Consent_Struct* s = (ServerOP_Consent_Struct*)pack->pBuffer;
			if(s->instance_id != 0)
			{
				ZoneServer* zs = zoneserver_list.FindByInstanceID(s->instance_id);
				if(zs) {
					if(!zs->SendPacket(pack))
						zlog(WORLD__ZONE_ERR, "Unable to send consent response back to player %s in instance %u.", s->ownername, zs->GetInstanceID());
				}
				else {
					zlog(WORLD__ZONE_ERR, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent_Response operation.", s->instance_id);
				}
			}
			else
			{
				ZoneServer* zs = zoneserver_list.FindByZoneID(s->zone_id);
				if(zs) {
					if(!zs->SendPacket(pack))
						zlog(WORLD__ZONE_ERR, "Unable to send consent response back to player %s in zone %s.", s->ownername, zs->GetZoneName());
				}
				else {
					zlog(WORLD__ZONE_ERR, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id);
				}
			}
			break;
		}

		case ServerOP_InstanceUpdateTime :
		{
			ServerInstanceUpdateTime_Struct *iut = (ServerInstanceUpdateTime_Struct*)pack->pBuffer;
			ZoneServer *zm = zoneserver_list.FindByInstanceID(iut->instance_id);
			if(zm)
			{
				zm->SendPacket(pack);
			}
			break;
		}
		case ServerOP_QGlobalUpdate:
		{
			if(pack->size != sizeof(ServerQGlobalUpdate_Struct))
			{
				break;
			}

			zoneserver_list.SendPacket(pack);
			break;		
		}

		case ServerOP_QGlobalDelete:
		{
			if(pack->size != sizeof(ServerQGlobalDelete_Struct))
			{
				break;
			}

			zoneserver_list.SendPacket(pack);
			break;		
		}

		case ServerOP_AdventureRequest:
		{
			adventure_manager.CalculateAdventureRequestReply((const char*)pack->pBuffer);
			break;
		}

		case ServerOP_AdventureRequestCreate:
		{
			adventure_manager.TryAdventureCreate((const char*)pack->pBuffer);
			break;
		}

		case ServerOP_AdventureDataRequest:
		{
			AdventureFinishEvent fe;
			while(adventure_manager.PopFinishedEvent((const char*)pack->pBuffer, fe))
			{
				adventure_manager.SendAdventureFinish(fe);
			}
			adventure_manager.GetAdventureData((const char*)pack->pBuffer);
			break;
		}

		case ServerOP_AdventureClickDoor:
		{
			ServerPlayerClickedAdventureDoor_Struct *pcad = (ServerPlayerClickedAdventureDoor_Struct*)pack->pBuffer;
			adventure_manager.PlayerClickedDoor(pcad->player, pcad->zone_id, pcad->id);
			break;
		}

		case ServerOP_AdventureLeave:
		{
			adventure_manager.LeaveAdventure((const char*)pack->pBuffer);
			break;
		}

		case ServerOP_AdventureCountUpdate:
		{
			ServerAdventureCount_Struct *sc = (ServerAdventureCount_Struct*)pack->pBuffer;
			adventure_manager.IncrementCount(sc->instance_id);
			break;
		}

		case ServerOP_AdventureAssaCountUpdate:
		{
			adventure_manager.IncrementAssassinationCount(*((uint16*)pack->pBuffer));
			break;
		}

		case ServerOP_AdventureZoneData:
		{
			adventure_manager.GetZoneData(*((uint16*)pack->pBuffer));
			break;
		}

		case ServerOP_AdventureLeaderboard:
		{
			ServerLeaderboardRequest_Struct *lr = (ServerLeaderboardRequest_Struct*)pack->pBuffer;
			adventure_manager.DoLeaderboardRequest(lr->player, lr->type);
			break;
		}

		case ServerOP_LSAccountUpdate:
		{
			zlog(WORLD__ZONE, "Received ServerOP_LSAccountUpdate packet from zone");
			loginserverlist.SendAccountUpdate(pack);
			break;
		}

		case ServerOP_UCSMailMessage: 
		{
			UCSLink.SendPacket(pack);
			break;
		}

		case ServerOP_QueryServGeneric:
		case ServerOP_Speech:
		case ServerOP_QSPlayerLogTrades:
		{
			QSLink.SendPacket(pack);
			break;
		}
		case ServerOP_QSPlayerLogHandins:
		{
			QSLink.SendPacket(pack);
			break;
		}
		case ServerOP_QSPlayerLogNPCKills:
		{
			QSLink.SendPacket(pack);
			break;
		}
		case ServerOP_QSPlayerLogDeletes:
		{
			QSLink.SendPacket(pack);
			break;
		}
		case ServerOP_QSPlayerLogMoves:
		{
			QSLink.SendPacket(pack);
			break;
		}
		case ServerOP_QSMerchantLogTransactions:
		{
			QSLink.SendPacket(pack);
			break;
		}
		case ServerOP_CZSignalClientByName:
		case ServerOP_CZMessagePlayer:
		case ServerOP_CZSignalClient:
		{
			zoneserver_list.SendPacket(pack);
			break;
		}
		case ServerOP_DepopAllPlayersCorpses:
		case ServerOP_DepopPlayerCorpse:
		case ServerOP_ReloadTitles:
		case ServerOP_SpawnStatusChange:
		case ServerOP_ReloadTasks:
		case ServerOP_ReloadWorld:
		case ServerOP_UpdateSpawn:
		{
			zoneserver_list.SendPacket(pack);
			break;
		}
		default:
		{
			zlog(WORLD__ZONE_ERR,"Unknown ServerOPcode from zone 0x%04x, size %d",pack->opcode,pack->size);
			DumpPacket(pack->pBuffer, pack->size);
			break;
		}
		}

		delete pack;
	} 
	return true;
}
示例#19
0
文件: make_H3orbits.c 项目: etmc/cvc
int make_H4orbits(int **qid, int **qid_count, double ***qid_val, int *nc) {

  int it, ix, iy, iz, iix, iit, n;
  int i0, i1, i2, i3;
  int isigma0, isigma1, isigma2, isigma3;
  int nqhat = -1;
  int Thp1  = T/2+1;
  int L = LX;
  int Lhp1  = L/2+1;
  int iq[4];
  int iq_perm[4], index_s;
  double q[4], qsq, q4;

  /* Nclasses = 1/4!/2^4 * (L+2)(L+4)(L+6)(L+8)  + the ones with odd t */
  int Nclasses = (L+2)*(L+4)*(L+6)*(L+8)/24/16 + T/4 * (L+2)*(L+4)*(L+6)/6/8;
  fprintf(stdout, "# Nclasses = %d\n", Nclasses);

  fprintf(stdout, "# allocating memory for qid_count\n");
  *qid_count = (int *)calloc(Nclasses, sizeof(int));

  fprintf(stdout, "# allocating memory for qid_val\n");
  *qid_val    = (double **)calloc(4, sizeof(double*));
  *(*qid_val) = (double * )calloc(4 * Nclasses, sizeof(double));
  (*qid_val)[1] = (*qid_val)[0] + Nclasses;
  (*qid_val)[2] = (*qid_val)[1] + Nclasses;
  (*qid_val)[3] = (*qid_val)[2] + Nclasses;

  fprintf(stdout, "# setting new fields to zero\n");
  for(it=0; it<Nclasses; it++) {
    (*qid_count)[it]  =  0;
    (*qid_val)[0][it] = -1.;
    (*qid_val)[1][it] = -1.;
    (*qid_val)[2][it] = -1.;
    (*qid_val)[3][it] = -1.;
  }

  if((*qid) == (int*)NULL) {
    fprintf(stdout, "# allocating memory for qid & setting to zero\n");
    *qid = (int *)calloc(VOLUME, sizeof(int));
    for(ix=0; ix<VOLUME; ix++) (*qid)[ix] = -1;
  }

  /* initialize the permutation tables */
  fprintf(stdout, "# initializing perm tabs\n");
  init_perm_tabs();

  fprintf(stdout, "# starting coordinate loops\n");
  nqhat = -1;
  for(it=0; it<Thp1; it++) {
    if(it%2==1) {
      for(ix=0; ix<Lhp1; ix++) {
        for(iy=0; iy<=ix; iy++) {
        for(iz=0; iz<=iy; iz++) {
          nqhat++;
  	  q[0] = 2. * sin( M_PI * (double)it / (double)T );
	  q[1] = 2. * sin( M_PI * (double)ix / (double)L );
	  q[2] = 2. * sin( M_PI * (double)iy / (double)L );
	  q[3] = 2. * sin( M_PI * (double)iz / (double)L );

          (*qid_val)[0][nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
          (*qid_val)[1][nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
          (*qid_val)[2][nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
          (*qid_val)[3][nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);

	  iq[0] = it; iq[1] = ix; iq[2] = iy; iq[3] = iz;
/*
          fprintf(stdout, "=====================================\n");
          fprintf(stdout, "odd it=%3d, ix=%3d, iy=%3d, iz=%3d, nqhat=%3d\n", it, ix, iy, iz, nqhat);
*/
          /* go through all permutations */
	  for(n=0; n<6; n++) { 
  	    iq_perm[0] = iq[perm_tab_3[n][0]+1];
	    iq_perm[1] = iq[perm_tab_3[n][1]+1];
	    iq_perm[2] = iq[perm_tab_3[n][2]+1];
/*
            fprintf(stdout, "-------------------------------------\n");
            fprintf(stdout, "%3d, %3d, %3d, %3d\n", iq[0], iq_perm[0], iq_perm[1], iq_perm[2]);
*/
            for(isigma0=0; isigma0<=1; isigma0++) {
              i0 = ( (1-isigma0)*iq[0] + isigma0*(T-iq[0]) ) % T;
            for(isigma1=0; isigma1<=1; isigma1++) {
              i1 = ( (1-isigma1)*iq_perm[0] + isigma1*(L-iq_perm[0]) ) % L;
            for(isigma2=0; isigma2<=1; isigma2++) {
              i2 = ( (1-isigma2)*iq_perm[1] + isigma2*(L-iq_perm[1]) ) % L;
            for(isigma3=0; isigma3<=1; isigma3++) {
              i3 = ( (1-isigma3)*iq_perm[2] + isigma3*(L-iq_perm[2]) ) % L;
  	      index_s = g_ipt[i0][i1][i2][i3];
/*              fprintf(stdout, "%3d, %3d, %3d, %3d; %5d, %5d\n", i0, i1, i2, i3, index_s, (*qid)[index_s]); */
  	      if((*qid)[index_s] == -1) {
                (*qid)[index_s] = nqhat;
	        (*qid_count)[nqhat] +=1;
	      }
            }
            }
            }
            }
	  }  /* end of n = 0, ..., 5 */
        }    /* of iz */
        }    /* of iy */
      }      /* of ix */
    }        /* of if it % 2 == 1 */
    else {   /* it is even */
      iit = it / 2;
      for(ix=0; ix<=iit; ix++) {
      for(iy=0; iy<=ix;  iy++) {
      for(iz=0; iz<=iy;  iz++) {
        nqhat++;
	q[0] = 2. * sin( M_PI * (double)it / (double)T );
	q[1] = 2. * sin( M_PI * (double)ix / (double)L );
	q[2] = 2. * sin( M_PI * (double)iy / (double)L );
	q[3] = 2. * sin( M_PI * (double)iz / (double)L );

        (*qid_val)[0][nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
        (*qid_val)[1][nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
        (*qid_val)[2][nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
        (*qid_val)[3][nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);

	iq[0] = iit; iq[1] = ix; iq[2] = iy; iq[3] = iz;
/*
        fprintf(stdout, "=====================================\n");
        fprintf(stdout, "even it=%3d, ix=%3d, iy=%3d, iz=%3d, nqhat=%3d\n", it, ix, iy, iz, nqhat);
*/
        for(n=0; n<24; n++) {
  	  iq_perm[0] = iq[perm_tab_4[n][0]];
	  iq_perm[1] = iq[perm_tab_4[n][1]];
	  iq_perm[2] = iq[perm_tab_4[n][2]];
	  iq_perm[3] = iq[perm_tab_4[n][3]];
/*
          fprintf(stdout, "-------------------------------------\n");
          fprintf(stdout, "%3d, %3d, %3d, %3d\n", iq_perm[0], iq_perm[1], iq_perm[2], iq_perm[3]);
*/
          for(isigma0=0; isigma0<=1; isigma0++) {
            i0 = ( 2*(1-isigma0)*iq_perm[0] + isigma0*(T-2*iq_perm[0]) ) % T;
          for(isigma1=0; isigma1<=1; isigma1++) {
            i1 = ( (1-isigma1)*iq_perm[1] + isigma1*(L-iq_perm[1]) ) % L;
          for(isigma2=0; isigma2<=1; isigma2++) {
            i2 = ( (1-isigma2)*iq_perm[2] + isigma2*(L-iq_perm[2]) ) % L;
          for(isigma3=0; isigma3<=1; isigma3++) {
            i3 = ( (1-isigma3)*iq_perm[3] + isigma3*(L-iq_perm[3]) ) % L;
  	    index_s = g_ipt[i0][i1][i2][i3];
/*            fprintf(stdout, "%3d, %3d, %3d, %3d; %5d, %5d\n", i0, i1, i2, i3, index_s, (*qid)[index_s]); */
  	    if((*qid)[index_s] == -1) {
              (*qid)[index_s] = nqhat;
	      (*qid_count)[nqhat] +=1;
	    }
          }
          }
          }
          }
        }    /* of n = 0, ..., 23  */
      }
      }
      }
    }        /* of else branch in if it % 2 == 1 */
  }          /* of it */
  fprintf(stdout, "# finished coordinate loops\n");

  /************************
   * test: print the lists 
   ************************/
/*
  for(it=0; it<T; it++) {
  for(ix=0; ix<L; ix++) {
  for(iy=0; iy<L; iy++) {
  for(iz=0; iz<L; iz++) {
    index_s = g_ipt[it][ix][iy][iz];
    q[0] = 2. * sin( M_PI * (double)it / (double)T );
    q[1] = 2. * sin( M_PI * (double)ix / (double)L );
    q[2] = 2. * sin( M_PI * (double)iy / (double)L );
    q[3] = 2. * sin( M_PI * (double)iz / (double)L );
    qsq = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
    q4 = q[0]*q[0]*q[0]*q[0] + q[1]*q[1]*q[1]*q[1] + 
         q[2]*q[2]*q[2]*q[2] + q[3]*q[3]*q[3]*q[3]; 

    fprintf(stdout, "t=%3d, x=%3d, y=%3d, z=%3d, qid=%8d\n", it, ix, iy, iz, (*qid)[index_s]);
  }
  }
  }
  }

  fprintf(stdout, "# n\tqid_count\tqid_val\n");
  for(n=0; n<Nclasses; n++) {
    fprintf(stdout, "%5d\t%8d\t%12.5e\t%12.5e\t%12.5e\t%12.5e\n",
      n, (*qid_count)[n], (*qid_val)[0][n], (*qid_val)[1][n],(*qid_val)[2][n],(*qid_val)[3][n]);
  }
*/

  *nc = Nclasses;

  return(0);

}
示例#20
0
文件: make_H3orbits.c 项目: etmc/cvc
int make_H3orbits(int **qid, int **qid_count, double ***qid_val, int *nc) {

  int it, ix, iy, iz, iix, n;
  int i0, i1, i2, i3;
  int isigma0, isigma1, isigma2, isigma3;
  int nqhat = -1;
  int Thp1  = T/2+1;
  int L = LX;
  int Lhp1  = L/2+1;
  int iq[4];
  int iq_perm[3], index_s;
  double q[4], qsq, q4;

  /* Nclasses = 1/48 * (L+2)(L+4)(L+6) */
  int Nclasses = (L*L*L+12*L*L+44*L+48)/48; 
  fprintf(stdout, "# Nclasses = %d x %d\n", Thp1, Nclasses);

  /* initialize the permutation tables */
  fprintf(stdout, "# initializing perm tabs\n");
  init_perm_tabs();


  fprintf(stdout, "# allocating memory for qid_count\n");
  *qid_count = (int *)calloc(Thp1 * Nclasses, sizeof(int));
  if(*qid_count==(int*)NULL) return(301);

  fprintf(stdout, "# allocating memory for qid_val\n");
  *qid_val = (double **)calloc(4, sizeof(double*));
  (*qid_val)[0] = (double*)calloc(4 * Thp1 * Nclasses, sizeof(double));
  if((*qid_val)[0]==(double*)NULL) return(302);
  (*qid_val)[1] = (*qid_val)[0] + Thp1 * Nclasses;
  (*qid_val)[2] = (*qid_val)[1] + Thp1 * Nclasses;
  (*qid_val)[3] = (*qid_val)[2] + Thp1 * Nclasses;

  fprintf(stdout, "# setting new fields to zero\n");
  for(it=0; it<Thp1*Nclasses; it++) {
    (*qid_count)[it]  =  0;
    (*qid_val)[0][it] = -1.;
    (*qid_val)[1][it] = -1.;
    (*qid_val)[2][it] = -1.;
    (*qid_val)[3][it] = -1.;
  }

  if((*qid) == (int*)NULL) {
    fprintf(stdout, "# allocating memory for qid & setting to zero\n");
    *qid = (int *)calloc(VOLUME, sizeof(int));
    if(*qid==(int*)NULL) return(303);
    for(ix=0; ix<VOLUME; ix++) (*qid)[ix] = -1;
  }

#ifdef _UNDEF
  for(it=0; it<Thp1; it++) {
    nqhat = -1;
    for(ix=0; ix<Lhp1; ix++) {
      for(iy=0; iy<=ix; iy++) {
      for(iz=0; iz<=iy; iz++) {
        nqhat++;
	q[0] = 2. * sin( M_PI * (double)it / (double)T );
	q[1] = 2. * sin( M_PI * (double)ix / (double)L );
	q[2] = 2. * sin( M_PI * (double)iy / (double)L );
	q[3] = 2. * sin( M_PI * (double)iz / (double)L );

        (*qid_val)[0][it*Nclasses+nqhat] = _sqr(q[0])+_sqr(q[1])+_sqr(q[2])+_sqr(q[3]);
        (*qid_val)[1][it*Nclasses+nqhat] = _qrt(q[0])+_qrt(q[1])+_qrt(q[2])+_qrt(q[3]);
        (*qid_val)[2][it*Nclasses+nqhat] = _hex(q[0])+_hex(q[1])+_hex(q[2])+_hex(q[3]);
        (*qid_val)[3][it*Nclasses+nqhat] = _oct(q[0])+_oct(q[1])+_oct(q[2])+_oct(q[3]);

	iq[0] = it; iq[1] = ix; iq[2] = iy; iq[3] = iz;
/*
        fprintf(stdout, "=====================================\n");
        fprintf(stdout, "it=%3d, ix=%3d, iy=%3d, iz=%3d, nqhat=%3d, id=%3d\n", it, ix, iy, iz, nqhat, it*Nclasses+nqhat);
*/
	for(n=0; n<6; n++) { 
	  iq_perm[0] = iq[perm_tab_3[n][0]+1];
	  iq_perm[1] = iq[perm_tab_3[n][1]+1];
	  iq_perm[2] = iq[perm_tab_3[n][2]+1];
/*          fprintf(stdout, "%3d, %3d, %3d, %3d\n", iq[0], iq_perm[0], iq_perm[1], iq_perm[2]); */
          for(isigma0=0; isigma0<=1; isigma0++) {
            i0 = ( (1-isigma0)*iq[0] + isigma0*(T-iq[0]) ) % T;
          for(isigma1=0; isigma1<=1; isigma1++) {
            i1 = ( (1-isigma1)*iq_perm[0] + isigma1*(L-iq_perm[0]) ) % L;
          for(isigma2=0; isigma2<=1; isigma2++) {
            i2 = ( (1-isigma2)*iq_perm[1] + isigma2*(L-iq_perm[1]) ) % L;
          for(isigma3=0; isigma3<=1; isigma3++) {
            i3 = ( (1-isigma3)*iq_perm[2] + isigma3*(L-iq_perm[2]) ) % L;
	    index_s = g_ipt[i0][i1][i2][i3];

/*            fprintf(stdout, "-------------------------------------\n"); */
/*            fprintf(stdout, "%3d, %3d, %3d, %3d; %5d, %5d\n", i0, i1, i2, i3, index_s, (*qid)[index_s]); */

	    if((*qid)[index_s] == -1) {
              (*qid)[index_s] = it*Nclasses + nqhat;
	      (*qid_count)[it*Nclasses+nqhat] +=1;
	    }

          }}}}
	}  
      }   
      } 
    }  
  }   
#endif
  /************************
   * test: print the lists 
   ************************/
/*
  for(it=0; it<T; it++) {
  for(ix=0; ix<L; ix++) {
  for(iy=0; iy<L; iy++) {
  for(iz=0; iz<L; iz++) {
    index_s = g_ipt[it][ix][iy][iz];
    q[0] = 2. * sin( M_PI * (double)it / (double)T );
    q[1] = 2. * sin( M_PI * (double)ix / (double)L );
    q[2] = 2. * sin( M_PI * (double)iy / (double)L );
    q[3] = 2. * sin( M_PI * (double)iz / (double)L );
    qsq = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
    q4 = q[0]*q[0]*q[0]*q[0] + q[1]*q[1]*q[1]*q[1] + 
         q[2]*q[2]*q[2]*q[2] + q[3]*q[3]*q[3]*q[3]; 

    fprintf(stdout, "t=%3d, x=%3d, y=%3d, z=%3d, qid=%8d\n", it, ix, iy, iz, (*qid)[index_s]);
  }
  }
  }
  }



  for(it=0; it<Thp1; it++) {
    for(n=0; n<Nclasses; n++) {
      fprintf(stdout, "t=%3d, n=%5d, qid_count=%8d, qid_val= %12.5e%12.5e%12.5e%12.5e\n",
        it, n, (*qid_count)[it*Nclasses+n], (*qid_val)[0][it*Nclasses+n], (*qid_val)[1][it*Nclasses+n],
        (*qid_val)[2][it*Nclasses+n],(*qid_val)[3][it*Nclasses+n]);
    }
  }
*/
  *nc = Thp1 * Nclasses;

  return(0);

}
int
_vprintf(void (*putc)(char c, void **param), void **param, const char *fmt, va_list ap)
{
    char buf[sizeof(long long)*8];
    char c, sign, *cp=buf;
    int  i;
    long long val = 0;
    int res = 0, length, width;
    int prepad, postpad, leading_zeros;
    int addr;
    
    while ((c = *fmt++) != '\0') {
        if (c == '%') {
            c = *fmt++;
            leading_zeros = (c == '0')?1:0;
            width = 0;
            prepad = 0;
            postpad = 0;
            while((c >= '0')&&(c <= '9')) {
                width = (width * 10) + (int)(c-'0');
                c = *fmt++;
            }

            // Process output
            switch (c) {
            case 'd':
                val = va_arg(ap, int); // up to dword
                length = _cvt(val, buf, 10, "0123456789", leading_zeros, width);
                if(length < width)
                    prepad = width - length;
                cp = buf;
                break;
            case 's':
                cp = va_arg(ap, char *);
                length = 0;
                while (cp[length] != '\0') length++;
                if(length < width)
                    postpad = width - length;
                if((width) && (length > width))
                    length = width; // truncate
                break;
            case 'c':
                c = va_arg(ap, int /*char*/);
                (*putc)(c, param);
                res++;
                continue;
            case 'p': // pointer
                addr = va_arg(ap, int);
                length = 7;
                _hex(addr, buf, length);
                cp = buf;
                break;
            case 'x': // any hex length
                addr = va_arg(ap, int); // up to dword
                _hex(addr, buf, width);
                length = width;
                cp = buf;
                break;
            case 'b': // byte
                addr = va_arg(ap, int); // byte
                length = 2;
                _hex(addr, buf, length);
                cp = buf;
                break;
            default:
                (*putc)('%', param);
                (*putc)(c, param);
                res += 2;
                continue;
            }
            while (prepad-- > 0) {
                (*putc)(' ', param);
                res++;
            }    
            while (length-- > 0) {
                c = *cp++;
                (*putc)(c, param);
                res++;
            }
            while (postpad-- > 0) {
                (*putc)(' ', param);
                res++;
            }    
        } else {
示例#22
0
文件: libdbms.c 项目: gitpan/RDFStore
extern          dbms_error_t
dbms_comms(
	   dbms * me,
	   int token,
	   int *retval,
	   DBT * v1,
	   DBT * v2,
	   DBT * r1,
	   DBT * r2
)
{
	int             errs = 5;
	int             err = 0;

	struct sigaction act, oact;
#ifdef TPS
	gettimeofday(&tstart, NULL);
#endif

	if (logfile) {
		char           *p1 = NULL;
		char           *p2 = NULL;
		if (v1)
			p1 = _hex(me, v1->size, v1->data);
		if (v2)
			p2 = _hex(me, v2->size, v2->data);

		_tlog("%s@%s:%d %s(%02d) >>> %s %s",
		      me->name, me->host,me->port, _token2name(token), token,
		      p1 ? p1 : "<null>",
		      p2 ? p2 : "<null>");
		if (p1) (*me->free)(p1);
		if (p2) (*me->free)(p2);
	}
	/*
	 * for now, SA_RESTART any interupted function calls
	 */
	act.sa_handler = SIG_IGN;
	sigemptyset(&act.sa_mask);
	act.sa_flags = SA_RESTART;

	sigaction(SIGPIPE, &act, &oact);
	if (retval)
		*retval = -1;

	/*
	 * now obviously this is wrong; we do _not_ want to continue during
	 * certain errors.. ah well..
	 */
	for (errs = 0; errs < 10; errs++) {
		if ((me->sockfd >= 0) &&
		  ((err = i_comms(me, token, retval, v1, v2, r1, r2)) == 0))
			break;

		/*
		 * we could of course exit on certain errors, but which ? we
		 * call recv, et.al.
		 */
		if (err == EAGAIN || err == EINTR)
			continue;

		/*
		 * If the DB on the other end reported an error - then it
		 * obviously is not a comms problem - so retrying makes no
		 * sense
		 */
		if (err == E_ERROR)
			break;

		sleep(errs * 2);
		shutdown(me->sockfd, 2);
		close(me->sockfd);

		me->sockfd = -1;/* mark that we have an issue */
		if (((err = reconnect(me)) == 0) &&
		    ((err = reselect(me)) == 0)) {
			if (errs)
				(*(me->callback)) (DBMS_EVENT_RECONNECT, errs);
		} else if (errs)
			(*(me->callback)) (DBMS_EVENT_WAITING, errs);
	};

#ifdef TPS
	gettimeofday(&tnow, NULL);
	ttps++;
	ttime +=
		(tnow.tv_sec - tstart.tv_sec) * 1000000 +
		(tnow.tv_usec - tstart.tv_usec) * 1;
#endif
	/*
	 * restore whatever it was before
	 */
	sigaction(SIGPIPE, &oact, &act);
	if (logfile) {
		char           *q1 = NULL;
		char           *q2 = NULL;
		if (r1)
			q1 = _hex(me, r1->size, r1->data);
		if (r2)
			q2 = _hex(me, r2->size, r2->data);

		_tlog("%s@%s:%d %s(%02d) <<< %s %s",
		      me->name, me->host,me->port, _token2name(token), token,
		      q1 ? q1 : "<null>",
		      q2 ? q2 : "<null>");
		if (q1) (*me->free)(q1);
		if (q2) (*me->free)(q2);
	}
	return err;
};
示例#23
0
bool LoginServer::Process() {
	const WorldConfig *Config=WorldConfig::get();

	if (statusupdate_timer.Check()) {
		this->SendStatus();
	}

	/************ Get all packets from packet manager out queue and process them ************/
	ServerPacket *pack = 0;
	while((pack = tcpc->PopPacket()))
	{
		_log(WORLD__LS_TRACE,"Recevied ServerPacket from LS OpCode 0x04x",pack->opcode);
		_hex(WORLD__LS_TRACE,pack->pBuffer,pack->size);

		switch(pack->opcode) {
			case 0:
				break;
			case ServerOP_KeepAlive: {
				// ignore this
				break;
			}
			case ServerOP_UsertoWorldReq: {
				UsertoWorldRequest_Struct* utwr = (UsertoWorldRequest_Struct*) pack->pBuffer;
				uint32 id = database.GetAccountIDFromLSID(utwr->lsaccountid);
				int16 status = database.CheckStatus(id);

				ServerPacket* outpack = new ServerPacket;
				outpack->opcode = ServerOP_UsertoWorldResp;
				outpack->size = sizeof(UsertoWorldResponse_Struct);
				outpack->pBuffer = new uchar[outpack->size];
				memset(outpack->pBuffer, 0, outpack->size);
				UsertoWorldResponse_Struct* utwrs = (UsertoWorldResponse_Struct*) outpack->pBuffer;
				utwrs->lsaccountid = utwr->lsaccountid;
				utwrs->ToID = utwr->FromID;

				if(Config->Locked == true)
				{
					if((status == 0 || status < 100) && (status != -2 || status != -1))
						utwrs->response = 0;
					if(status >= 100)
						utwrs->response = 1;
				}
				else {
					utwrs->response = 1;
				}

				int32 x = Config->MaxClients;
				if( (int32)numplayers >= x && x != -1 && x != 255 && status < 80)
					utwrs->response = -3;

				if(status == -1)
					utwrs->response = -1;
				if(status == -2)
					utwrs->response = -2;

				utwrs->worldid = utwr->worldid;
				SendPacket(outpack);
				delete outpack;
				break;
			}
			case ServerOP_LSClientAuth: {
				ServerLSClientAuth* slsca = (ServerLSClientAuth*) pack->pBuffer;

				if (RuleI(World, AccountSessionLimit) >= 0) {
					// Enforce the limit on the number of characters on the same account that can be
					// online at the same time.
					client_list.EnforceSessionLimit(slsca->lsaccount_id);
				}

				client_list.CLEAdd(slsca->lsaccount_id, slsca->name, slsca->key, slsca->worldadmin, slsca->ip, slsca->local);
				break;
			}
			case ServerOP_LSFatalError: {
	#ifndef IGNORE_LS_FATAL_ERROR
				WorldConfig::DisableLoginserver();
				_log(WORLD__LS_ERR, "Login server responded with FatalError. Disabling reconnect.");
	#else
			_log(WORLD__LS_ERR, "Login server responded with FatalError.");
	#endif
				if (pack->size > 1) {
					_log(WORLD__LS_ERR, "     %s",pack->pBuffer);
				}
				break;
			}
			case ServerOP_SystemwideMessage: {
				ServerSystemwideMessage* swm = (ServerSystemwideMessage*) pack->pBuffer;
				zoneserver_list.SendEmoteMessageRaw(0, 0, 0, swm->type, swm->message);
				break;
			}
			case ServerOP_LSRemoteAddr: {
				if (!Config->WorldAddress.length()) {
					WorldConfig::SetWorldAddress((char *)pack->pBuffer);
					_log(WORLD__LS, "Loginserver provided %s as world address",pack->pBuffer);
				}
				break;
			}
			case ServerOP_LSAccountUpdate: {
				_log(WORLD__LS, "Received ServerOP_LSAccountUpdate packet from loginserver");
				CanAccountUpdate = true;
				break;
			}
			default:
			{
				_log(WORLD__LS_ERR, "Unknown LSOpCode: 0x%04x size=%d",(int)pack->opcode,pack->size);
	DumpPacket(pack->pBuffer, pack->size);
				break;
			}
		}
		delete pack;
	}

	return true;
}