Esempio n. 1
0
    void handler::receive_packets()
    {
        if(socket_.can_recv())
        {
            yuki::net::pak pak(256);
            pak.endg(yuki::net::endianess::little);

            if(socket_.recv_pak(pak))
            {
                uint16_t header = 0;
                pak >> header;

                switch(header)
                {
                case  packet::header_ping: // Ping-request
                {
                    yuki::time ping;
                    pak >> ping;
                    yuki::log("< Ping? (" + ping.str("hh:mm:ss") + ")");
                    baic::packet p;
                    yuki::time now;
                    p.pak << static_cast<uint16_t>(packet::header_pong);
                    p.pak << now;
                    p.pak.bake();
                    packets_.push(p);
                    yuki::log("> Pong! (" + now.str("hh:mm:ss") + ")");
                    break;
                }
                default: break;
                }
            }
void PPAppReceiver::sendFn(PPClsPack& args) {
	PPCallPack pak(&args, "");
	char* data; int dataLen;
	dataLen = pak.compress(data);

	coreEnt->rsend(data, dataLen, opId);
}
Esempio n. 3
0
QuestEntry* WorldServer::getQuestById(const dword_t questId) {
	std::map<const DWORD, QuestEntry*>::iterator i = this->questData.begin();
	while (i != this->questData.end()) {
		QuestEntry* entry = (*i).second;
#ifdef __ROSE_DEBUG__
		dword_t currentQuestId = entry->getQuestId();
		if(currentQuestId == questId) {
#else
		if (entry->getQuestId() == questId) {
#endif
			return entry;
		}
		i++;
	}
	return nullptr;
}

bool ChatService::sendDebugMessage(Player* receiver, const char* msg, ...) {
	va_list args; va_start(args, msg);
	std::string aMsg = QuickInfo::convertVarsToString(msg, args);
	va_end(args);
	Packet pak(PacketID::World::Response::LOCAL_CHAT);
	pak.addWord(receiver->getLocalId());
	pak.addString("[DEBUG] ");
	pak.addString(aMsg.c_str());
	pak.addByte(0x00);
	return receiver->sendData(pak);
}
Esempio n. 4
0
bool ChatService::sendAnnouncement(Entity* entity, const char* aMsg, ...) {
	va_list args; va_start(args, aMsg);
	std::string msg = QuickInfo::convertVarsToString(aMsg, args);
	va_end(args);
	Packet pak(PacketID::World::Response::ANNOUNCEMENT);
	pak.addString(msg.c_str());
	pak.addByte(0x00);
	return mainServer->sendToAll(pak);
}
Esempio n. 5
0
bool NPC::convertTo(const word_t newType) {
	this->ai = mainServer->getAIData(newType);
	this->data = mainServer->getNPCData(newType);

	this->updateStats();

	Packet pak(PacketID::World::Response::CONVERT_MONSTER);
	pak.addWord(this->getLocalId());
	pak.addWord(newType);
	return this->sendToVisible(pak);
}
Esempio n. 6
0
bool ChatService::sendShout(Entity* entity, const char* aMsg, ...) {
	va_list args; va_start(args, aMsg);
	std::string msg = QuickInfo::convertVarsToString(aMsg, args);
	va_end(args);
	Packet pak(PacketID::World::Response::SHOUT_CHAT);
	pak.addString(entity->getName().c_str());
	pak.addByte(0x00);
	pak.addString( msg.c_str() );
	pak.addByte(0x00);
	return entity->sendToMap(pak);
}
Esempio n. 7
0
bool ChatService::sendWhisper(const char* from, Player* to, const char *aMsg, ...) {
	if(to == nullptr)
		return false;
	va_list args; va_start(args, aMsg);
	std::string msg = QuickInfo::convertVarsToString(aMsg, args);
	va_end(args);
	Packet pak(PacketID::World::Response::WHISPER_CHAT);
	pak.addString(from); pak.addByte(0x00);
	pak.addString(msg); pak.addByte(0x00);
	return to->sendData(pak);
}
Esempio n. 8
0
bool ChatService::sendMessage(Entity* sender, const char* msg) {
	Packet pak(PacketID::World::Response::LOCAL_CHAT);
	pak.addWord(sender->getLocalId());
	pak.addString(msg);
	pak.addByte(0x00);
	if (msg[0] == '/') {
		GMService::executeCommand(dynamic_cast<Player*>(sender), pak);
		return true;
	}
	return sender->sendToVisible(pak);
}
Esempio n. 9
0
 std::string zip( const bistrings &p )
 {
     moon9::pak pak(moon9::paktype::ZIP);
     for( auto &it : p )
     {
         moon9::pakfile pf;
         pf["filename"] = it.first;
         pf["content"] = it.second;
         pak.push_back( pf );
     }
     return pak.bin();
 }
Esempio n. 10
0
bool ChatService::sendWhisper(Player* from, Player* to, const char *msg) {
	if(from == nullptr)
		return false;
	Packet pak(PacketID::World::Response::WHISPER_CHAT);
	pak.addString(from->getName()); pak.addByte(0x00);
	if(!to) {
		pak.addByte(0x00);
		return from->sendData(pak);
	}
	pak.addString(msg); 
	pak.addByte(0x00);
	return to->sendData(pak);
}
Esempio n. 11
0
bool NPC::setPositionVisually(const position_t& pos) {
	Entity* target = this->combat.getTarget();

	Packet pak(PacketID::World::Response::MOVEMENT_MONSTER);
	pak.addWord(this->getLocalId());
	pak.addWord(target != nullptr ? target->getLocalId() : 0x00);
	pak.addWord(this->getMovementSpeed());
	pak.addFloat(static_cast<float>(pos.x));
	pak.addFloat(static_cast<float>(pos.y));
	pak.addWord(0xcdcd); //Z-Axis
	pak.addByte(this->status.getStance().asBYTE());

	this->sendToVisible(pak);
	return true;
}
Esempio n. 12
0
    bistrings zip( const std::string &s )
    {
        bistrings bs;

        moon9::pak pak(moon9::paktype::ZIP);
        pak.bin( s );

        for( auto &it : pak )
        {
            moon9::pakfile &pf = (it);
            bistring b;

            b.first = pf["filename"];
            b.second = pf["content"];

            bs.push_back( b );
        }

        return bs;
    }
Esempio n. 13
0
    bool handler::connect(const yuki::string& host, const uint16_t port)
    {
        if(!socket_.connect(host, port))
        {
            yuki::log("Could not connect to server: " + host + ":" + yuki::string::dec(port));
            return false;
        }

        yuki::log("Connected to " + socket_.address());
        yuki::log("Waiting for server verification...");

        if(!socket_.can_recv(10 * 1000))
        {
            yuki::log("Connection timeout 10 seconds");
            return false;
        }

        yuki::net::pak pak(256);
        pak.endg(yuki::net::endianess::little);

        if(!socket_.recv_pak(pak))
        {
            yuki::log("Could not receive verification packet");
            return false;
        }

        uint16_t header = 0;
        pak >> header >> server_version_ >> server_time_;

        if(header != packet::header_welcome)
        {
            yuki::log(socket_.address() + " is not a valid BattleAI server");
            return false;
        }

        yuki::log("Server verified as BattleAI Server version " + yuki::string::dec(server_version_));
        yuki::log("Current server time is: " + server_time_.str("DD.MM.YYYY - hh:mm:ss"));
        connected_ = true;

        return true;
    }
Esempio n. 14
0
void main()
{
//
	int gdriver = DETECT, gmode, errorcode;
	initgraph(&gdriver, &gmode, "..\\bgi");
	errorcode = graphresult();
	if (errorcode != grOk)  /* an error occurred */
	{
		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();
		exit(1);             /* return with error code */
	}
	left = getmaxx() / 4 - 50;
	top = getmaxy() / 4 - 50;
	right = getmaxx() / 4 + 200;
	bottom = getmaxy() / 4 + 50;
	int selopt = 1;
	mainmenu();
	d_op(1, 0);
	char cursor;
	do {
		cursor = getch();
		switch( cursor )
		{
		case 80://B
			if( selopt < szopt ) {
				selopt++;
				d_op(selopt, 1);
			}
			break;
		case 72://up
			if( selopt > 1 ) {
				selopt--;
				d_op(selopt, -1);
			}
			break;
		case 13:
			cleardevice();
			gotoxy( 1, 1 );
			switch(selopt)
			{
			case 1: //add new set
				if( sn != 10 ) //Exception Handling: 10 element array
				{
					char new_set_choice;
					do
					{
						s[sn].input();
						sn++;
						cout << "\nDo you want to add more set (y/n): ";
						new_set_choice = getch();
					}
					while( new_set_choice != 'n' );
				}
				else//Exception Handling Message
				{
					cout << "\n\nOnly ten sets are allowed!";
					pak(); gc();
				}
				break;
			case 2://display all sets
				disp();
				getch();
				break;
			case 3://perform set functions
				char s1[20], s2[20];
				int i1=-1, i2=-1;
				disp();
				if( sn < 2 ) {
					cout << "\nThere should be at least two sets";
					pak();
					gc();
					break;
				}
				cout << "\nEnter name for set # 1: "; cin >> s1;
				int l;
				for( l=0; l < sn; l++ )
					if( strcmp( s[l].set_name, s1 ) == 0 ) {
						i1 = l;
						break;
					}
				if( i1 == -1 ) {
					cout << "\nSet not found";
					pak(); gc();
					break;
				}
				cout << "Enter name for set # 2: "; cin >> s2;
				for( l=0; l < sn; l++ ) {
					if( strcmp( s[l].set_name, s2 ) == 0 ) {
						i2 = l;
						break;
					}
				}
				if( i2 == -1 ) {
					cout << "\nSet not found";
					pak(); gc();
					break;
				}
				if( i1 != -1 && i2 != -1 ) {
					s[i1].disp();
					s[i2].disp();
					s[i1].Union( &s[i2] );
					s[i1].intersection( &s[i2] );
					s[i1].diff( &s[i2] );
					s[i1].memb( &s[i2] );
					pak();
				}
				getch();
				break;
			case 4:
				exit(0);
				break;
			default:
				cout << "\n\nWrong option ";
				pak(); gc();
				break;
			}
			cleardevice();
			mainmenu();
			d_op(selopt, 0);
			break;
		default:
			break;
		}
	} while( cursor != 27 );
	closegraph();
}// end main
Esempio n. 15
0
void main() {
	strcpy( c1.set_name, "CO101's Student" );
	strcpy( c2.set_name, "CO102's Student" );
	strcpy( non.set_name, "Not taking Course" );
	int gdriver = DETECT, gmode, errorcode;
	initgraph(&gdriver, &gmode, "..\\bgi");
	errorcode = graphresult();
	if (errorcode != grOk)  /* an error occurred */
	{
		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();
		exit(1);             /* return with error code */
	}
	left = getmaxx() / 4 - 50;
	top = getmaxy() / 4 - 50;
	right = getmaxx() / 4 + 300;
	bottom = getmaxy() / 4 + 100;
	int selopt = 1;
	mainmenu();
	d_op(1, 0);
	char cursor;
	do {
		cursor = getch();
		switch( cursor )
		{
		case 80://B
			if( selopt < szopt ) {
				selopt++;
				d_op(selopt, 1);
			}
			break;
		case 72://up
			if( selopt > 1 ) {
				selopt--;
				d_op(selopt, -1);
			}
			break;
		case 13:
			cleardevice();
			gotoxy( 1, 1 );
			switch(selopt)
			{
			case 1: //add new student
				char add_stu;
				do {
					bs.insert();
					cout << "\nAdd more (y/n): ";
					add_stu = getch();
				} while( add_stu != 'n' );
				break;
			case 2:
				cout << endl;
				c1.disp_stu();
				c2.disp_stu();
				pak(); gc();
				break;
			case 3:
				cout << endl;
				non.disp_stu();
				pak(); gc();
				break;
			case 4:
				c1.sort();
				c2.sort();
				non.sort();
				cout << "\n\nSimple Sorted values"
					<< "\n--------------------\n";
				c1.disp_stu();
				c2.disp_stu();
				non.disp_stu();
				pak(); gc();
				break;
			case 5:
				c1.q_sort( 1, c1.max );
				c2.q_sort( 1, c2.max );
				non.q_sort( 1, non.max );
				cout << "\n\nQuick Sorted values"
					<< "\n-------------------\n";
				c1.disp_stu();
				c2.disp_stu();
				non.disp_stu();
				pak(); gc();
				break;
			case 6:
				bs.p(); pak(); gc();
				break;
			case 7:
				cout << endl;
				c1.disp_stu();
				c2.disp_stu();
				non.disp_stu();
				cout << "\n\nStudents course lists taking;";
				c1.diff_stu( &c2 );
				c1.union_stu( &c2 );
				c1.intersection_stu( &c2 );
				pak(); gc();
				break;
			case 8: exit(0); break;
			default:
				cout << "\n\nWrong option ";
				pak(); gc();
				break;
			}
			cleardevice();
			mainmenu();
			d_op(selopt, 0);
			break;
		default:
			break;
		}
	} while( cursor != 27 );
	closegraph();
}// end main