Ejemplo n.º 1
0
int initialize(lua_State* state)
{
	Database* mysqldb = makeDatabase(state);

	if (!mysqldb) return 0;

	std::string error;
	if (!mysqldb->Initialize(error))
	{
		LUA->PushBool(false);
		LUA->PushString(error.c_str());
		delete mysqldb;
		return 2;
	}

	UserData* userdata = (UserData*)LUA->NewUserdata(sizeof(UserData));
	userdata->data = mysqldb;
	userdata->type = DATABASE_ID;

	int uData = LUA->ReferenceCreate();

	LUA->ReferencePush(iRefDatabases);
	LUA->PushNumber(mysqldb->GetTableIndex());
	LUA->ReferencePush(uData);
	LUA->SetTable(-3);

	LUA->ReferencePush(uData);
	LUA->ReferenceFree(uData);
	LUA->CreateMetaTableType(DATABASE_NAME, DATABASE_ID);
	LUA->SetMetaTable(-2);
	return 1;
}
Ejemplo n.º 2
0
int DBConnect(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call Connect on a shutdown database");
		return 0;
	}

	if (mysqldb->IsConnected()) {
		LUA->ThrowError("Attempted to call Connect on an already connected database");
		return 0;
	}

	std::string error;
	bool success = mysqldb->Initialize(error);

	LUA->PushBool(success);

	if (!success)
	{
		LUA->PushString(error.c_str());
		delete mysqldb;
		return 2;
	}
	return 1;
}
Ejemplo n.º 3
0
int _tmain(int argc, _TCHAR* argv[])
{
	Log.loglevel = 999;
	const char * username = "";
	const char * password = "";
	const char * dbname = "";
	if(!sDatabase.Initialize("localhost", 3306, username, password, dbname, 1, 65536))
	{
		Log.Error("SQL", "could not connect");
		return 1;
	}
	QueryResult * result = sDatabase.Query("SELECT guid, skills FROM characters");
	do 
	{
		char * skills = strdup(result->Fetch()[1].GetString());
		if(strchr(skills, ',') != 0)
		{
			// need to convert
			uint32 i = 0;
			stringstream ss;
			char * start = skills;
			char * end;
			for(;;)
			{
				// skill, skill+1, <add>0
				end = strchr(start, ',');
				if(!end)
					break;
				*end = '\0';
				uint32 val = atoi(start);
				start = end + 1;
				ss << val << " ";
				++i;
				if(!(i % 2))
					ss << "0 ";
			}

			sDatabase.Execute("UPDATE characters SET skills = '%s' WHERE guid = %u", ss.str().c_str(), result->Fetch()[0].GetUInt32());
			Log.Debug("SQL", "UPDATE characters SET skills = '%s' WHERE guid = %u", ss.str().c_str(), result->Fetch()[0].GetUInt32());
		}
	} while(result->NextRow());
	delete result;
	sDatabase.Shutdown();
	Log.Success("Program", "Exit normally");
	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char* argv[])
{
    std::string  map;
    std::string  style;

    glutInit(&argc, argv);                 // Initialize GLUT

    if (argc!=3) {
        std::cerr << "DrawMap <map directory> <style-file>" << std::endl;
        return 1;
    }

    map=argv[1];
    style=argv[2];

    if (!database.Initialize(map,
                             style)) {
        std::cerr << "Cannot open database" << std::endl;
    }

    drawParameter.SetDrawWaysWithFixedWidth(false);
    drawParameter.SetRenderSeaLand(true);
    drawParameter.SetDebugPerformance(true);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA);

    glutInitWindowSize(width, height);      // Set the window's initial width & height
    glutInitWindowPosition(50, 50);    // Position the window's initial top-left corner
    window=glutCreateWindow("DrawMapOpenGL"); // Create a window with the given title

    glutDisplayFunc(OnDisplay);          // Register display callback handler for window re-paint
    glutKeyboardFunc(OnKeyPressed);      // Keyboard handling
    glutReshapeFunc(OnResize);

    OnInit();

    glutMainLoop();                    // Enter the event-processing loop

    return 0;
}