Witamy w Nieoficjalnym polskim support'cie AMX Mod X
Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
|
Guest Message by DevFuse
Wklejka 9yqa87am3ows dodana przez Kawon, 23.07.2012 21:35
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346. 347. 348. 349. 350. 351. 352. 353. 354. 355. 356. 357. 358. 359. 360. 361. 362. 363. 364. 365. 366. 367. 368. 369. 370. 371. 372. 373. 374. 375. 376. 377. 378. 379. 380. 381. 382. 383. 384. 385. 386. 387. 388. 389. 390. 391. 392.
/* // Use this to create the table in MySQL CREATE TABLE IF NOT EXISTS `pm_save` ( `SAVE_KEY` varchar(34) binary NOT NULL default '', `XPS` varchar(255) binary NOT NULL default '', `LAST_PLAY_DATE` timestamp(14) NOT NULL, PRIMARY KEY (`SAVE_KEY`) ) TYPE=MyISAM COMMENT='PokeMod Saving Table'; // now it should work fine //if using MySQL and are updating from v1.2.0 Beta J2 or lower, run these queries ALTER TABLE `pm_save` ADD `LAST_PLAY_DATE` timestamp(14) NOT NULL; ALTER TABLE `pm_save` MODIFY `XPS` varchar(255) binary NOT NULL default ''; //if using MySQL and are updating from v1.2.0 Beta K2 or lower, run this query UPDATE `pm_save` SET `LAST_PLAY_DATE`=SYSDATE() */ // This makes sure theres no gaps in PlayersPoke // Example: // From: 5 390 0 0 10 200 16 1000 // To: 5 390 10 200 16 1000 0 0 public RefreshPoke(id) { if(Safari() || !id || !Pokemod_Connected(id)) return new PlaceHolder[3][MAX_POKES] new i, p = 0; for(i = 0; i<MAX_ACTIVE_POKES; i++){ if( ValidPoke( PlayersPoke[id][i] ) ){ PlaceHolder[0][p] = PlayersPoke[id][i]; PlaceHolder[1][p] = PlayersXP[id][i]; PlaceHolder[2][p] = PlayersLevels[id][i]; p++; } } for(i = p; i<MAX_ACTIVE_POKES; i++){ PlayersPoke[id][i] = 0; PlayersXP[id][i] = 0; PlayersLevels[id][i] = 0; } p = MAX_ACTIVE_POKES; for(i = MAX_ACTIVE_POKES; i<MAX_POKES; i++){ if( ValidPoke( PlayersPoke[id][i] ) ){ PlaceHolder[0][p] = PlayersPoke[id][i]; PlaceHolder[1][p] = PlayersXP[id][i]; PlaceHolder[2][p] = PlayersLevels[id][i]; p++; } } for(i = p; i<MAX_POKES; i++){ PlayersPoke[id][i] = 0; PlayersXP[id][i] = 0; PlayersLevels[id][i] = 0; } for(i = 0; i<MAX_POKES; i++){ PlayersPoke[id][i] = PlaceHolder[0][i]; PlayersXP[id][i] = PlaceHolder[1][i]; PlayersLevels[id][i] = PlaceHolder[2][i]; } if(!SwitchPoke(id, Pokemon[id])){ for(i=0; i<MAX_ACTIVE_POKES; i++){ if(SwitchPoke(id, PlayersPoke[id][i])) break; } } } /////////////////////////////////////////// // For MYSQL, find the database to use // /////////////////////////////////////////// #if SAVE==SAVE_MYSQL public adminCopyVault(id) { if (!(get_user_flags(id)&ADMIN_RCON ) && id!=0) return PLUGIN_HANDLED mySQLConnect() if ( gMySQL <= SQL_FAILED ) return PLUGIN_HANDLED //Turn Persistant on for this function gPersistentTemp = true // Open up the vault file - read line by line if ( !file_exists(g_VaultFile) ) return PLUGIN_HANDLED console_print(id,"Please wait while the XP data is copied") // Read through the file looking for shinfo entries new parm[2] parm[0] = id parm[1] = 0 adminCopyVHelper(parm) //Rest of this is done in the helper function return PLUGIN_HANDLED } public adminCopyVHelper(parm[]) { //Get data from parm new id = parm[0] new nextLine = parm[1] // Read through the file looking for shinfo entries new lengthRead new data[512], Right[401], Left[111] while ((nextLine = read_file(g_VaultFile,nextLine,data,511,lengthRead)) != 0) { if ( lengthRead > 0 && equali(data, "PokeMod", 7) ) { strbreak(data, Left, 110, Right, 400) replace(Left,110,"PokeMod-",EMPTY) replace_all(Left,34,"`","`") replace_all(Left,34,"'","'") writeData(0, Left, Right) if (nextLine % 200 == 0) { parm[1] = nextLine console_print(id,"Delaying a few seconds before copying the next set of entries") set_task(3.0, "adminCopyVHelper",0,parm,2) return } } } //If it makes it this far it must be done copying // OK now load the XP for any players playing load_all(); console_print(id,"Saved XP has been copied from the vault to the MySQL Database Successfully") //Set Persistent back how it was gPersistentTemp = false //Closes the connection if set not to be persistent close_mysql() } public saving_init() { register_pokeadmincmd("vault_to_sql","adminCopyVault", ADMIN_RCON,"- Copies vault XP to MySQL, should only be done once.") // Verify the type of DBI module that is loaded is supported dbi_type(SQLtype, 15); if (equali(SQLtype, g_MySQL)) { SQL_TYPE = SQL_MYSQL; } else if (equali(SQLtype, g_SQLite)) { SQL_TYPE = SQL_SQLITE; } else { SQL_TYPE = SQL_NONE; debugMessage(_,_,"XP", "Unsupported database type found (%s), the supported databases are %s or %s", SQLtype, g_MySQL, g_SQLite); return; } debugMessage( 0,7,"XP", "MYSQL registering done" ) } public mySQLConnect() { gPersistent = get_ppcvar_num(pm_mysql_persistent) if ( gMySQL >= SQL_OK ) { if (!gPersistent && !gPersistentTemp) close_mysql() else return } new host[64],user[32],pass[32],db[32],error[128] get_ppcvar_string(pm_mysql_host,host,63) get_ppcvar_string(pm_mysql_user,user,31) get_ppcvar_string(pm_mysql_pass,pass,31) get_ppcvar_string(pm_mysql_db,db,31) if ( !strlen(host) && !strlen(user) && !strlen(db) ) { get_cvar_string("amx_mysql_host",host,63) get_cvar_string("amx_mysql_user",user,31) get_cvar_string("amx_mysql_pass",pass,31) get_cvar_string("amx_mysql_db",db,31) } // Set a default DB if it's SQLite and the user didn't supply one if ( SQL_TYPE == SQL_SQLITE && strlen(db) < 1 ) copy( db, 127, "addons/amxmodx/data/amxx.db" ); gMySQL = dbi_connect(host,user,pass,db,error,127) if (gMySQL <= SQL_FAILED) { debugMessage(0,0,"XP", "MySQL connect error: '%s' (%s,%s,%s)",error,host,user,db) return } //Only try to create the tables once else if (CreateTables) { new sql[512] new Result:retval if ( SQL_TYPE == SQL_SQLITE ){ if ( !sqlite_table_exists( gMySQL, "pm_save" ) ){ copy(sql, 511, "CREATE TABLE `pm_save` ( `SAVE_KEY` varchar(34) binary NOT NULL default '', `XPS` varchar(255) binary NOT NULL default '', `LAST_PLAY_DATE` timestamp(14) NOT NULL, PRIMARY KEY (`SAVE_KEY`) ) TYPE=MyISAM COMMENT='PokeMod Saving Table'") retval = dbi_query(gMySQL,sql) if (retval <= RESULT_FAILED) { dbi_error(gMySQL,error,127) debugMessage(0,0,"XP", "Error Making Tables: '%s' - '%s'", error, sql) return } if ( SQL_TYPE == SQL_SQLITE ) { new IntegrityCheck[64]; copy(sql, 511, "PRAGMA integrity_check"); new Result:res = dbi_query(gMySQL, sql); // Check for an error if ( res < RESULT_NONE ) { dbi_error(gMySQL,error,127) debugMessage(0,0,"XP", "Error Making Tables: '%s' - '%s'", error, sql) return; } // Get the integrity check value while ( res && dbi_nextrow(res) > 0 ) { dbi_result(res, "integrity_check", IntegrityCheck, 63); } // Free the result dbi_free_result(res); // Check to make sure the integrity check passed if ( !equali(IntegrityCheck, "ok") ) { // Should we disable saving here? debugMessage(_,_,"XP", "SQL Lite integrity check failed"); return; } // Do some synchronous crap format(sql, 511, "PRAGMA synchronous = %d", SQLITE_SYNC_OFF); dbi_query(gMySQL, sql); } } } else { copy(sql, 511, "CREATE TABLE IF NOT EXISTS `pm_save` ( `SAVE_KEY` varchar(34) binary NOT NULL default '', `XPS` varchar(255) binary NOT NULL default '', `LAST_PLAY_DATE` timestamp(14) NOT NULL, PRIMARY KEY (`SAVE_KEY`) ) TYPE=MyISAM COMMENT='PokeMod Saving Table'") retval = dbi_query(gMySQL,sql) if (retval <= RESULT_FAILED) { dbi_error(gMySQL,error,127) debugMessage(0,0,"XP", "Error Making Tables: '%s' - '%s'", error, sql) return } } CreateTables = false } } writeData(x, key[], xps_to_save[]) { mySQLConnect() if ( gMySQL <= SQL_FAILED ) return debugMessage( x, 8,"XP", "Trying to save XP data: '%s' - '%s'", key, xps_to_save) new error[128],sql[512] new Result:retval, Result:retvalins //Thanks to HC for help with writing more efficient queries //Check if this user has an entry already, if not make one formatex(sql, 511, "SELECT * FROM `pm_save` WHERE `SAVE_KEY` = '%s'", key) retval = dbi_query(gMySQL,sql) if (retval <= RESULT_FAILED) { dbi_error(gMySQL,error,127) debugMessage(0,0,"XP", "Error Querying MySQL DB for %s: '%s' - '%s'", key, error, sql) return } else if (!dbi_nextrow(retval)) { formatex(sql, 511, "INSERT INTO `pm_save` (SAVE_KEY) VALUES ('%s')", key ) retvalins = dbi_query(gMySQL,sql) if (retvalins <= RESULT_FAILED) { dbi_error(gMySQL,error,127) debugMessage(0,0,"XP", "Error Writing MySQL XP for %s: '%s' - '%s'", key, error, sql) return } } if (retval >= RESULT_OK) dbi_free_result(retval) //Update users entry with current data formatex(sql, 511, "UPDATE `pm_save` SET `XPS`='%s' WHERE (SAVE_KEY='%s')",xps_to_save,key) retval = dbi_query(gMySQL,sql) if (retval <= RESULT_FAILED) { dbi_error(gMySQL,error,127) debugMessage(0,0,"XP", "Error Writing MySQL XP for %s: '%s' - '%s'", key, error, sql) return } //Closes the connection if set not to be persistent close_mysql() } public close_mysql() { if (gMySQL <= SQL_FAILED || gPersistent || gPersistentTemp) return dbi_close(gMySQL) } public saving_end() { if ( gMySQL <= SQL_FAILED ) return dbi_close(gMySQL) } #endif #if SAVE==SAVE_VAULT writeData(x, key[], xps_to_save[]) { debugMessage(x, 8,"XP", "Trying to save XP data: '%s' - '%s'", key, xps_to_save) new vaultSaveKey[40] //Make the key to save to formatex(vaultSaveKey,39,"PokeMod-%s",key) set_vaultdata(vaultSaveKey, xps_to_save) } #endif #if SAVE==SAVE_NVAULT public saving_init() { register_pokeadmincmd("vault_to_nvault","adminCopyVault", ADMIN_RCON,"- Copies vault XP to NVault, should only be done once.") nvault_db = nvault_open("pm_save") debugMessage( 0,7,"XP", "NVault registering done" ) } writeData(x, key[], xps_to_save[]) { debugMessage( x, 8,"XP", "Trying to save XP data: '%s' - '%s'", key, xps_to_save) new vaultSaveKey[40] //Make the key to save to formatex(vaultSaveKey,39,"PokeMod-%s",key) nvault_set(nvault_db, key, xps_to_save) } public adminCopyVault(id) { if (!(get_user_flags(id)&ADMIN_RCON ) && id!=0) return PLUGIN_HANDLED // Open up the vault file - read line by line if ( !file_exists(g_VaultFile) ) return PLUGIN_HANDLED console_print(id,"Please wait while the XP data is copied") // Read through the file looking for shinfo entries new parm[2] parm[0] = id parm[1] = 0 adminCopyVHelper(parm) //Rest of this is done in the helper function return PLUGIN_HANDLED } public adminCopyVHelper(parm[]) { //Get data from parm new id = parm[0] new nextLine = parm[1] // Read through the file looking for shinfo entries new lengthRead new data[512], Right[401], Left[111] while ((nextLine = read_file(g_VaultFile,nextLine,data,511,lengthRead)) != 0) { if ( lengthRead > 0 && equali(data, "PokeMod", 7) ) { strbreak(data, Left, 110, Right, 400) replace(Left,110,"PokeMod-",EMPTY) writeData(0, Left, Right) if (nextLine % 200 == 0) { parm[1] = nextLine console_print(id,"Delaying a few seconds before copying the next set of entries") set_task(3.0, "adminCopyVHelper",0,parm,2) return } } } //If it makes it this far it must be done copying // OK now load the XP for any players playing load_all(); console_print(id,"Saved XP has been copied from the vault to the NVault Database Successfully") } #endif public LoadXP(id) { if( !PM_Loaded ){ Pokemod_Connect(id,0); return false; } if( g_isWild[id] > 0 ) return true if( !SaveXPon() ) return true new key[35] if( getSaveKey(id, key, true) ) { #if SAVE==SAVE_NVAULT new Right[1501] new vaultSaveKey[40], time formatex(vaultSaveKey,39,"PokeMod-%s",key) nvault_lookup(nvault_db, key, Right, 1500, time) #endif #if SAVE==SAVE_VAULT new Right[1501] new vaultSaveKey[40] formatex(vaultSaveKey,39,"PokeMod-%s",key) get_vaultdata(vaultSaveKey, Right, 1500) #endif #if SAVE==SAVE_MYSQL new Right[1501] new sql[512], error[128] new Result:retvalxp mySQLConnect() if ( gMySQL <= SQL_FAILED ) return false formatex(sql, 511, "SELECT `XPS` FROM `pm_save` WHERE `SAVE_KEY` = '%s'", key) retvalxp = dbi_query(gMySQL,sql) if(retvalxp <= RESULT_FAILED){ dbi_error(gMySQL,error,127) debugMessage(id,0,"XP", "Error Querying MySQL DB for %s: '%s' - '%s'", key, error, sql) //Closes the connection if set not to be persistent close_mysql() return false } else if (!dbi_nextrow(retvalxp)) { dbi_error(gMySQL,error,127) debugMessage(id,3,"XP", "No Saved XP Loaded for %s: '%s'", key, error) if (retvalxp >= RESULT_OK) dbi_free_result(retvalxp) //Closes the connection if set not to be persistent close_mysql() Pokemod_Connect(id,-1);
Dodanych wklejek: 4031
Powered By (Pav32) Pastebin © 2011