diff --git a/data/wordlist.txt b/data/wordlist.txt new file mode 100644 index 000000000..fb0a9e35e --- /dev/null +++ b/data/wordlist.txt @@ -0,0 +1,1296 @@ +1111 acid +1112 acorn +1113 acre +1114 acts +1115 afar +1116 affix +1121 aged +1122 agent +1123 agile +1124 aging +1125 agony +1126 ahead +1131 aide +1132 aids +1133 aim +1134 ajar +1135 alarm +1136 alias +1141 alibi +1142 alien +1143 alike +1144 alive +1145 aloe +1146 aloft +1151 aloha +1152 alone +1153 amend +1154 amino +1155 ample +1156 amuse +1161 angel +1162 anger +1163 angle +1164 ankle +1165 apple +1166 april +1211 apron +1212 aqua +1213 area +1214 arena +1215 argue +1216 arise +1221 armed +1222 armor +1223 army +1224 aroma +1225 array +1226 arson +1231 art +1232 ashen +1233 ashes +1234 atlas +1235 atom +1236 attic +1241 audio +1242 avert +1243 avoid +1244 awake +1245 award +1246 awoke +1251 axis +1252 bacon +1253 badge +1254 bagel +1255 baggy +1256 baked +1261 baker +1262 balmy +1263 banjo +1264 barge +1265 barn +1266 bash +1311 basil +1312 bask +1313 batch +1314 bath +1315 baton +1316 bats +1321 blade +1322 blank +1323 blast +1324 blaze +1325 bleak +1326 blend +1331 bless +1332 blimp +1333 blink +1334 bloat +1335 blob +1336 blog +1341 blot +1342 blunt +1343 blurt +1344 blush +1345 boast +1346 boat +1351 body +1352 boil +1353 bok +1354 bolt +1355 boned +1356 boney +1361 bonus +1362 bony +1363 book +1364 booth +1365 boots +1366 boss +1411 botch +1412 both +1413 boxer +1414 breed +1415 bribe +1416 brick +1421 bride +1422 brim +1423 bring +1424 brink +1425 brisk +1426 broad +1431 broil +1432 broke +1433 brook +1434 broom +1435 brush +1436 buck +1441 bud +1442 buggy +1443 bulge +1444 bulk +1445 bully +1446 bunch +1451 bunny +1452 bunt +1453 bush +1454 bust +1455 busy +1456 buzz +1461 cable +1462 cache +1463 cadet +1464 cage +1465 cake +1466 calm +1511 cameo +1512 canal +1513 candy +1514 cane +1515 canon +1516 cape +1521 card +1522 cargo +1523 carol +1524 carry +1525 carve +1526 case +1531 cash +1532 cause +1533 cedar +1534 chain +1535 chair +1536 chant +1541 chaos +1542 charm +1543 chase +1544 cheek +1545 cheer +1546 chef +1551 chess +1552 chest +1553 chew +1554 chief +1555 chili +1556 chill +1561 chip +1562 chomp +1563 chop +1564 chow +1565 chuck +1566 chump +1611 chunk +1612 churn +1613 chute +1614 cider +1615 cinch +1616 city +1621 civic +1622 civil +1623 clad +1624 claim +1625 clamp +1626 clap +1631 clash +1632 clasp +1633 class +1634 claw +1635 clay +1636 clean +1641 clear +1642 cleat +1643 cleft +1644 clerk +1645 click +1646 cling +1651 clink +1652 clip +1653 cloak +1654 clock +1655 clone +1656 cloth +1661 cloud +1662 clump +1663 coach +1664 coast +1665 coat +1666 cod +2111 coil +2112 coke +2113 cola +2114 cold +2115 colt +2116 coma +2121 come +2122 comic +2123 comma +2124 cone +2125 cope +2126 copy +2131 coral +2132 cork +2133 cost +2134 cot +2135 couch +2136 cough +2141 cover +2142 cozy +2143 craft +2144 cramp +2145 crane +2146 crank +2151 crate +2152 crave +2153 crawl +2154 crazy +2155 creme +2156 crepe +2161 crept +2162 crib +2163 cried +2164 crisp +2165 crook +2166 crop +2211 cross +2212 crowd +2213 crown +2214 crumb +2215 crush +2216 crust +2221 cub +2222 cult +2223 cupid +2224 cure +2225 curl +2226 curry +2231 curse +2232 curve +2233 curvy +2234 cushy +2235 cut +2236 cycle +2241 dab +2242 dad +2243 daily +2244 dairy +2245 daisy +2246 dance +2251 dandy +2252 darn +2253 dart +2254 dash +2255 data +2256 date +2261 dawn +2262 deaf +2263 deal +2264 dean +2265 debit +2266 debt +2311 debug +2312 decaf +2313 decal +2314 decay +2315 deck +2316 decor +2321 decoy +2322 deed +2323 delay +2324 denim +2325 dense +2326 dent +2331 depth +2332 derby +2333 desk +2334 dial +2335 diary +2336 dice +2341 dig +2342 dill +2343 dime +2344 dimly +2345 diner +2346 dingy +2351 disco +2352 dish +2353 disk +2354 ditch +2355 ditzy +2356 dizzy +2361 dock +2362 dodge +2363 doing +2364 doll +2365 dome +2366 donor +2411 donut +2412 dose +2413 dot +2414 dove +2415 down +2416 dowry +2421 doze +2422 drab +2423 drama +2424 drank +2425 draw +2426 dress +2431 dried +2432 drift +2433 drill +2434 drive +2435 drone +2436 droop +2441 drove +2442 drown +2443 drum +2444 dry +2445 duck +2446 duct +2451 dude +2452 dug +2453 duke +2454 duo +2455 dusk +2456 dust +2461 duty +2462 dwarf +2463 dwell +2464 eagle +2465 early +2466 earth +2511 easel +2512 east +2513 eaten +2514 eats +2515 ebay +2516 ebony +2521 ebook +2522 echo +2523 edge +2524 eel +2525 eject +2526 elbow +2531 elder +2532 elf +2533 elk +2534 elm +2535 elope +2536 elude +2541 elves +2542 email +2543 emit +2544 empty +2545 emu +2546 enter +2551 entry +2552 envoy +2553 equal +2554 erase +2555 error +2556 erupt +2561 essay +2562 etch +2563 evade +2564 even +2565 evict +2566 evil +2611 evoke +2612 exact +2613 exit +2614 fable +2615 faced +2616 fact +2621 fade +2622 fall +2623 false +2624 fancy +2625 fang +2626 fax +2631 feast +2632 feed +2633 femur +2634 fence +2635 fend +2636 ferry +2641 fetal +2642 fetch +2643 fever +2644 fiber +2645 fifth +2646 fifty +2651 film +2652 filth +2653 final +2654 finch +2655 fit +2656 five +2661 flag +2662 flaky +2663 flame +2664 flap +2665 flask +2666 fled +3111 flick +3112 fling +3113 flint +3114 flip +3115 flirt +3116 float +3121 flock +3122 flop +3123 floss +3124 flyer +3125 foam +3126 foe +3131 fog +3132 foil +3133 folic +3134 folk +3135 food +3136 fool +3141 found +3142 fox +3143 foyer +3144 frail +3145 frame +3146 fray +3151 fresh +3152 fried +3153 frill +3154 frisk +3155 from +3156 front +3161 frost +3162 froth +3163 frown +3164 froze +3165 fruit +3166 gag +3211 gains +3212 gala +3213 game +3214 gap +3215 gas +3216 gave +3221 gear +3222 gecko +3223 geek +3224 gem +3225 genre +3226 gift +3231 gig +3232 gills +3233 given +3234 giver +3235 glad +3236 glass +3241 glide +3242 gloss +3243 glove +3244 glow +3245 glue +3246 goal +3251 going +3252 golf +3253 gong +3254 good +3255 gooey +3256 goofy +3261 gore +3262 gown +3263 grab +3264 grain +3265 grant +3266 grape +3311 graph +3312 grasp +3313 grass +3314 grave +3315 gravy +3316 gray +3321 green +3322 greet +3323 grew +3324 grid +3325 grief +3326 grill +3331 grip +3332 grit +3333 groom +3334 grope +3335 growl +3336 grub +3341 grunt +3342 guide +3343 gulf +3344 gulp +3345 gummy +3346 guru +3351 gush +3352 gut +3353 guy +3354 habit +3355 half +3356 halo +3361 halt +3362 happy +3363 harm +3364 hash +3365 hasty +3366 hatch +3411 hate +3412 haven +3413 hazel +3414 hazy +3415 heap +3416 heat +3421 heave +3422 hedge +3423 hefty +3424 help +3425 herbs +3426 hers +3431 hub +3432 hug +3433 hula +3434 hull +3435 human +3436 humid +3441 hump +3442 hung +3443 hunk +3444 hunt +3445 hurry +3446 hurt +3451 hush +3452 hut +3453 ice +3454 icing +3455 icon +3456 icy +3461 igloo +3462 image +3463 ion +3464 iron +3465 islam +3466 issue +3511 item +3512 ivory +3513 ivy +3514 jab +3515 jam +3516 jaws +3521 jazz +3522 jeep +3523 jelly +3524 jet +3525 jiffy +3526 job +3531 jog +3532 jolly +3533 jolt +3534 jot +3535 joy +3536 judge +3541 juice +3542 juicy +3543 july +3544 jumbo +3545 jump +3546 junky +3551 juror +3552 jury +3553 keep +3554 keg +3555 kept +3556 kick +3561 kilt +3562 king +3563 kite +3564 kitty +3565 kiwi +3566 knee +3611 knelt +3612 koala +3613 kung +3614 ladle +3615 lady +3616 lair +3621 lake +3622 lance +3623 land +3624 lapel +3625 large +3626 lash +3631 lasso +3632 last +3633 latch +3634 late +3635 lazy +3636 left +3641 legal +3642 lemon +3643 lend +3644 lens +3645 lent +3646 level +3651 lever +3652 lid +3653 life +3654 lift +3655 lilac +3656 lily +3661 limb +3662 limes +3663 line +3664 lint +3665 lion +3666 lip +4111 list +4112 lived +4113 liver +4114 lunar +4115 lunch +4116 lung +4121 lurch +4122 lure +4123 lurk +4124 lying +4125 lyric +4126 mace +4131 maker +4132 malt +4133 mama +4134 mango +4135 manor +4136 many +4141 map +4142 march +4143 mardi +4144 marry +4145 mash +4146 match +4151 mate +4152 math +4153 moan +4154 mocha +4155 moist +4156 mold +4161 mom +4162 moody +4163 mop +4164 morse +4165 most +4166 motor +4211 motto +4212 mount +4213 mouse +4214 mousy +4215 mouth +4216 move +4221 movie +4222 mower +4223 mud +4224 mug +4225 mulch +4226 mule +4231 mull +4232 mumbo +4233 mummy +4234 mural +4235 muse +4236 music +4241 musky +4242 mute +4243 nacho +4244 nag +4245 nail +4246 name +4251 nanny +4252 nap +4253 navy +4254 near +4255 neat +4256 neon +4261 nerd +4262 nest +4263 net +4264 next +4265 niece +4266 ninth +4311 nutty +4312 oak +4313 oasis +4314 oat +4315 ocean +4316 oil +4321 old +4322 olive +4323 omen +4324 onion +4325 only +4326 ooze +4331 opal +4332 open +4333 opera +4334 opt +4335 otter +4336 ouch +4341 ounce +4342 outer +4343 oval +4344 oven +4345 owl +4346 ozone +4351 pace +4352 pagan +4353 pager +4354 palm +4355 panda +4356 panic +4361 pants +4362 panty +4363 paper +4364 park +4365 party +4366 pasta +4411 patch +4412 path +4413 patio +4414 payer +4415 pecan +4416 penny +4421 pep +4422 perch +4423 perky +4424 perm +4425 pest +4426 petal +4431 petri +4432 petty +4433 photo +4434 plank +4435 plant +4436 plaza +4441 plead +4442 plot +4443 plow +4444 pluck +4445 plug +4446 plus +4451 poach +4452 pod +4453 poem +4454 poet +4455 pogo +4456 point +4461 poise +4462 poker +4463 polar +4464 polio +4465 polka +4466 polo +4511 pond +4512 pony +4513 poppy +4514 pork +4515 poser +4516 pouch +4521 pound +4522 pout +4523 power +4524 prank +4525 press +4526 print +4531 prior +4532 prism +4533 prize +4534 probe +4535 prong +4536 proof +4541 props +4542 prude +4543 prune +4544 pry +4545 pug +4546 pull +4551 pulp +4552 pulse +4553 puma +4554 punch +4555 punk +4556 pupil +4561 puppy +4562 purr +4563 purse +4564 push +4565 putt +4566 quack +4611 quake +4612 query +4613 quiet +4614 quill +4615 quilt +4616 quit +4621 quota +4622 quote +4623 rabid +4624 race +4625 rack +4626 radar +4631 radio +4632 raft +4633 rage +4634 raid +4635 rail +4636 rake +4641 rally +4642 ramp +4643 ranch +4644 range +4645 rank +4646 rant +4651 rash +4652 raven +4653 reach +4654 react +4655 ream +4656 rebel +4661 recap +4662 relax +4663 relay +4664 relic +4665 remix +4666 repay +5111 repel +5112 reply +5113 rerun +5114 reset +5115 rhyme +5116 rice +5121 rich +5122 ride +5123 rigid +5124 rigor +5125 rinse +5126 riot +5131 ripen +5132 rise +5133 risk +5134 ritzy +5135 rival +5136 river +5141 roast +5142 robe +5143 robin +5144 rock +5145 rogue +5146 roman +5151 romp +5152 rope +5153 rover +5154 royal +5155 ruby +5156 rug +5161 ruin +5162 rule +5163 runny +5164 rush +5165 rust +5166 rut +5211 sadly +5212 sage +5213 said +5214 saint +5215 salad +5216 salon +5221 salsa +5222 salt +5223 same +5224 sandy +5225 santa +5226 satin +5231 sauna +5232 saved +5233 savor +5234 sax +5235 say +5236 scale +5241 scam +5242 scan +5243 scare +5244 scarf +5245 scary +5246 scoff +5251 scold +5252 scoop +5253 scoot +5254 scope +5255 score +5256 scorn +5261 scout +5262 scowl +5263 scrap +5264 scrub +5265 scuba +5266 scuff +5311 sect +5312 sedan +5313 self +5314 send +5315 sepia +5316 serve +5321 set +5322 seven +5323 shack +5324 shade +5325 shady +5326 shaft +5331 shaky +5332 sham +5333 shape +5334 share +5335 sharp +5336 shed +5341 sheep +5342 sheet +5343 shelf +5344 shell +5345 shine +5346 shiny +5351 ship +5352 shirt +5353 shock +5354 shop +5355 shore +5356 shout +5361 shove +5362 shown +5363 showy +5364 shred +5365 shrug +5366 shun +5411 shush +5412 shut +5413 shy +5414 sift +5415 silk +5416 silly +5421 silo +5422 sip +5423 siren +5424 sixth +5425 size +5426 skate +5431 skew +5432 skid +5433 skier +5434 skies +5435 skip +5436 skirt +5441 skit +5442 sky +5443 slab +5444 slack +5445 slain +5446 slam +5451 slang +5452 slash +5453 slate +5454 slaw +5455 sled +5456 sleek +5461 sleep +5462 sleet +5463 slept +5464 slice +5465 slick +5466 slimy +5511 sling +5512 slip +5513 slit +5514 slob +5515 slot +5516 slug +5521 slum +5522 slurp +5523 slush +5524 small +5525 smash +5526 smell +5531 smile +5532 smirk +5533 smog +5534 snack +5535 snap +5536 snare +5541 snarl +5542 sneak +5543 sneer +5544 sniff +5545 snore +5546 snort +5551 snout +5552 snowy +5553 snub +5554 snuff +5555 speak +5556 speed +5561 spend +5562 spent +5563 spew +5564 spied +5565 spill +5566 spiny +5611 spoil +5612 spoke +5613 spoof +5614 spool +5615 spoon +5616 sport +5621 spot +5622 spout +5623 spray +5624 spree +5625 spur +5626 squad +5631 squat +5632 squid +5633 stack +5634 staff +5635 stage +5636 stain +5641 stall +5642 stamp +5643 stand +5644 stank +5645 stark +5646 start +5651 stash +5652 state +5653 stays +5654 steam +5655 steep +5656 stem +5661 step +5662 stew +5663 stick +5664 sting +5665 stir +5666 stock +6111 stole +6112 stomp +6113 stony +6114 stood +6115 stool +6116 stoop +6121 stop +6122 storm +6123 stout +6124 stove +6125 straw +6126 stray +6131 strut +6132 stuck +6133 stud +6134 stuff +6135 stump +6136 stung +6141 stunt +6142 suds +6143 sugar +6144 sulk +6145 surf +6146 sushi +6151 swab +6152 swan +6153 swarm +6154 sway +6155 swear +6156 sweat +6161 sweep +6162 swell +6163 swept +6164 swim +6165 swing +6166 swipe +6211 swirl +6212 swoop +6213 swore +6214 syrup +6215 tacky +6216 taco +6221 tag +6222 take +6223 tall +6224 talon +6225 tamer +6226 tank +6231 taper +6232 taps +6233 tarot +6234 tart +6235 task +6236 taste +6241 tasty +6242 taunt +6243 thank +6244 thaw +6245 theft +6246 theme +6251 thigh +6252 thing +6253 think +6254 thong +6255 thorn +6256 those +6261 throb +6262 thud +6263 thumb +6264 thump +6265 thus +6266 tiara +6311 tidal +6312 tidy +6313 tiger +6314 tile +6315 tilt +6316 tint +6321 tiny +6322 trace +6323 track +6324 trade +6325 train +6326 trait +6331 trap +6332 trash +6333 tray +6334 treat +6335 tree +6336 trek +6341 trend +6342 trial +6343 tribe +6344 trick +6345 trio +6346 trout +6351 truce +6352 truck +6353 trump +6354 trunk +6355 try +6356 tug +6361 tulip +6362 tummy +6363 turf +6364 tusk +6365 tutor +6366 tutu +6411 tux +6412 tweak +6413 tweet +6414 twice +6415 twine +6416 twins +6421 twirl +6422 twist +6423 uncle +6424 uncut +6425 undo +6426 unify +6431 union +6432 unit +6433 untie +6434 upon +6435 upper +6436 urban +6441 used +6442 user +6443 usher +6444 utter +6445 value +6446 vapor +6451 vegan +6452 venue +6453 verse +6454 vest +6455 veto +6456 vice +6461 video +6462 view +6463 viral +6464 virus +6465 visa +6466 visor +6511 vixen +6512 vocal +6513 voice +6514 void +6515 volt +6516 voter +6521 vowel +6522 wad +6523 wafer +6524 wager +6525 wages +6526 wagon +6531 wake +6532 walk +6533 wand +6534 wasp +6535 watch +6536 water +6541 wavy +6542 wheat +6543 whiff +6544 whole +6545 whoop +6546 wick +6551 widen +6552 widow +6553 width +6554 wife +6555 wifi +6556 wilt +6561 wimp +6562 wind +6563 wing +6564 wink +6565 wipe +6566 wired +6611 wiry +6612 wise +6613 wish +6614 wispy +6615 wok +6616 wolf +6621 womb +6622 wool +6623 woozy +6624 word +6625 work +6626 worry +6631 wound +6632 woven +6633 wrath +6634 wreck +6635 wrist +6636 xerox +6641 yahoo +6642 yam +6643 yard +6644 year +6645 yeast +6646 yelp +6651 yield +6652 yo-yo +6653 yodel +6654 yoga +6655 yoyo +6656 yummy +6661 zebra +6662 zero +6663 zesty +6664 zippy +6665 zone +6666 zoom diff --git a/src/engine/server/sql_server.h b/src/engine/server/sql_server.h index d789f4491..3b6a39a8e 100644 --- a/src/engine/server/sql_server.h +++ b/src/engine/server/sql_server.h @@ -30,6 +30,7 @@ public: const char* GetPass() { return m_aPass; } const char* GetIP() { return m_aIp; } int GetPort() { return m_Port; } + sql::Connection *Connection() const { return m_pConnection; } static int ms_NumReadServer; static int ms_NumWriteServer; diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index d4781775e..57191b9a6 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -693,17 +693,20 @@ void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData) if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; - const char* pCode = pResult->GetString(0); + const char* pCode = ""; + if(pResult->NumArguments() > 0) + pCode = pResult->GetString(0); + char aCountry[5]; - if(str_length(pCode) > 3 && pCode[0] >= 'A' && pCode[0] <= 'Z' && pCode[1] >= 'A' + if(str_length(pCode) >= 3 && pCode[0] >= 'A' && pCode[0] <= 'Z' && pCode[1] >= 'A' && pCode[1] <= 'Z' && pCode[2] >= 'A' && pCode[2] <= 'Z') { - if(pCode[3] == ' ') + if(str_length(pCode) == 3 || pCode[3] == ' ') { str_copy(aCountry, pCode, 4); pCode = str_skip_whitespaces_const(pCode + 4); } - else if(str_length(pCode) > 4 && pCode[4] == ' ') + else if(str_length(pCode) == 4 || (str_length(pCode) > 4 && pCode[4] == ' ')) { str_copy(aCountry, pCode, 5); pCode = str_skip_whitespaces_const(pCode + 5); diff --git a/src/game/server/ddracechat.h b/src/game/server/ddracechat.h index e0d3ec894..48787a00c 100644 --- a/src/game/server/ddracechat.h +++ b/src/game/server/ddracechat.h @@ -27,7 +27,7 @@ CHAT_COMMAND("dnd", "", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_NONTEEHISTORIC, ConD CHAT_COMMAND("mapinfo", "?r[map]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConMapInfo, this, "Show info about the map with name r gives (current map by default)") CHAT_COMMAND("timeout", "?s[code]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTimeout, this, "Set timeout protection code s") CHAT_COMMAND("practice", "?i['0'|'1']", CFGFLAG_CHAT|CFGFLAG_SERVER, ConPractice, this, "Enable cheats (currently only /rescue) for your current team's run, but you can't earn a rank") -CHAT_COMMAND("save", "r[code]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSave, this, "Save team with code r to current server. To save to another server, use '/save s r' where s = server (case-sensitive: GER, RUS, etc) and r = code.") +CHAT_COMMAND("save", "?r[code]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSave, this, "Save team with code r to current server. To save to another server, use '/save s r' where s = server (case-sensitive: GER, RUS, etc) and r = code.") CHAT_COMMAND("load", "?r[code]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConLoad, this, "Load with code r. /load to check your existing saves") CHAT_COMMAND("map", "?r[map]", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_NONTEEHISTORIC, ConMap, this, "Vote a map by name") CHAT_COMMAND("rankteam", "?r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamRank, this, "Shows the team rank of player with name r (your team rank by default)") diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 1bafc8aa4..58278433f 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -6,11 +6,14 @@ #include #include +#include +#include #include #include #include #include +#include #include #include @@ -100,6 +103,18 @@ void CSqlScore::ExecPlayerThread( pThreadName); } +void CSqlScore::GeneratePassphrase(char *pBuf, int BufSize) +{ + for(int i = 0; i < 3; i++) + { + if(i != 0) + str_append(pBuf, " ", BufSize); + // TODO: decide if the slight bias towards lower numbers is ok + int Rand = m_Prng.RandomBits() % m_aWordlist.size(); + str_append(pBuf, m_aWordlist[Rand].c_str(), BufSize); + } +} + LOCK CSqlScore::ms_FailureFileLock = lock_create(); void CSqlScore::OnShutdown() @@ -169,6 +184,33 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) : ((CGameControllerDDRace*)(pGameServer->m_pController))->m_pInitResult = InitResult; Tmp->m_Map = g_Config.m_SvMap; + IOHANDLE File = GameServer()->Storage()->OpenFile("wordlist.txt", IOFLAG_READ, IStorage::TYPE_ALL); + if(!File) + { + dbg_msg("sql", "failed to open wordlist"); + Server()->SetErrorShutdown("sql open wordlist error"); + return; + } + + uint64 aSeed[2]; + secure_random_fill(aSeed, sizeof(aSeed)); + m_Prng.Seed(aSeed); + CLineReader LineReader; + LineReader.Init(File); + char *pLine; + while((pLine = LineReader.Get())) + { + char Word[32] = {0}; + sscanf(pLine, "%*s %31s", Word); + Word[31] = 0; + m_aWordlist.push_back(Word); + } + if(m_aWordlist.size() < 1000) + { + dbg_msg("sql", "too few words in wordlist"); + Server()->SetErrorShutdown("sql too few words in wordlist"); + return; + } thread_init_and_detach(CSqlExecData::ExecSqlFunc, new CSqlExecData(Init, Tmp), "SqlScore constructor"); @@ -1463,11 +1505,13 @@ void CSqlScore::SaveTeam(int ClientID, const char* Code, const char* Server) pController->m_Teams.SetSaving(Team, SaveResult); CSqlTeamSave *Tmp = new CSqlTeamSave(SaveResult); - Tmp->m_Code = Code; - Tmp->m_Map = g_Config.m_SvMap; + str_copy(Tmp->m_Code, Code, sizeof(Tmp->m_Code)); + str_copy(Tmp->m_Map, g_Config.m_SvMap, sizeof(Tmp->m_Map)); Tmp->m_pResult->m_SaveID = RandomUuid(); str_copy(Tmp->m_Server, Server, sizeof(Tmp->m_Server)); str_copy(Tmp->m_ClientName, this->Server()->ClientName(ClientID), sizeof(Tmp->m_ClientName)); + Tmp->m_aGeneratedCode[0] = '\0'; + GeneratePassphrase(Tmp->m_aGeneratedCode, sizeof(Tmp->m_aGeneratedCode)); pController->m_Teams.KillSavedTeam(ClientID, Team); char aBuf[512]; @@ -1487,7 +1531,7 @@ bool CSqlScore::SaveTeamThread(CSqlServer* pSqlServer, const CSqlDatam_pResult->m_SaveID, aSaveID, UUID_MAXSTRSIZE); - sqlstr::CSqlString<65536> SaveState = pData->m_pResult->m_SavedTeam.GetString(); + char *pSaveState = pData->m_pResult->m_SavedTeam.GetString(); if(HandleFailure) { if (!g_Config.m_SvSqlFailureFile[0]) @@ -1498,13 +1542,16 @@ bool CSqlScore::SaveTeamThread(CSqlServer* pSqlServer, const CSqlData SaveState = pSaveState; + sqlstr::CSqlString<128> Code = pData->m_aGeneratedCode; + sqlstr::CSqlString<128> Map = pData->m_Map; char aBuf[65536]; str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %%s_saves(Savegame, Map, Code, Timestamp, Server, SaveID, DDNet7) " "VALUES ('%s', '%s', '%s', CURRENT_TIMESTAMP(), '%s', '%s', false)", - SaveState.ClrStr(), pData->m_Map.ClrStr(), - pData->m_Code.ClrStr(), pData->m_Server, aSaveID + SaveState.ClrStr(), Map.ClrStr(), + Code.ClrStr(), pData->m_Server, aSaveID ); io_write(File, aBuf, str_length(aBuf)); io_write_newline(File); @@ -1514,63 +1561,98 @@ bool CSqlScore::SaveTeamThread(CSqlServer* pSqlServer, const CSqlDatam_pResult->m_Status = CSqlSaveResult::SAVE_SUCCESS; strcpy(pData->m_pResult->m_aBroadcast, "Database connection failed, teamsave written to a file instead. Admins will add it manually in a few days."); - + str_format(pData->m_pResult->m_aMessage, sizeof(pData->m_pResult->m_aMessage), + "Team successfully saved by %s. Use '/load %s' to continue", + pData->m_ClientName, Code.Str()); return true; } lock_unlock(ms_FailureFileLock); dbg_msg("sql", "ERROR: Could not save Teamsave, NOT even to a file"); return false; } - else + + try { - try + char aBuf[65536]; + str_format(aBuf, sizeof(aBuf), "lock tables %s_saves write;", pSqlServer->GetPrefix()); + pSqlServer->executeSql(aBuf); + + char Code[128] = {0}; + str_format(aBuf, sizeof(aBuf), "SELECT Savegame FROM %s_saves WHERE Code = ? AND Map = ?", pSqlServer->GetPrefix()); + std::unique_ptr pPrepStmt; + std::unique_ptr pResult; + pPrepStmt.reset(pSqlServer->Connection()->prepareStatement(aBuf)); + bool UseCode = false; + if(pData->m_Code[0] != '\0') { - char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "lock tables %s_saves write;", pSqlServer->GetPrefix()); - pSqlServer->executeSql(aBuf); - str_format(aBuf, sizeof(aBuf), - "SELECT Savegame " - "FROM %s_saves " - "WHERE Code = '%s' AND Map = '%s';", - pSqlServer->GetPrefix(), pData->m_Code.ClrStr(), pData->m_Map.ClrStr()); - pSqlServer->executeSqlQuery(aBuf); - - if (pSqlServer->GetResults()->rowsCount() == 0) + pPrepStmt->setString(1, pData->m_Code); + pPrepStmt->setString(2, pData->m_Map); + pResult.reset(pPrepStmt->executeQuery()); + if(pResult->rowsCount() == 0) { - char aBuf[65536]; + UseCode = true; + str_copy(Code, pData->m_Code, sizeof(Code)); + } + } + if(!UseCode) + { + // use random generated passphrase if save code exists or no save code given + pPrepStmt->setString(1, pData->m_aGeneratedCode); + pPrepStmt->setString(2, pData->m_Map); + pResult.reset(pPrepStmt->executeQuery()); + if(pResult->rowsCount() == 0) + { + UseCode = true; + str_copy(Code, pData->m_aGeneratedCode, sizeof(Code)); + } + } - str_format(aBuf, sizeof(aBuf), - "INSERT IGNORE INTO %s_saves(Savegame, Map, Code, Timestamp, Server, SaveID, DDNet7) " - "VALUES ('%s', '%s', '%s', CURRENT_TIMESTAMP(), '%s', '%s', false)", - pSqlServer->GetPrefix(), SaveState.ClrStr(), pData->m_Map.ClrStr(), - pData->m_Code.ClrStr(), pData->m_Server, aSaveID - ); - dbg_msg("sql", "%s", aBuf); - pSqlServer->executeSql(aBuf); + if(UseCode) + { + str_format(aBuf, sizeof(aBuf), + "INSERT IGNORE INTO %s_saves(Savegame, Map, Code, Timestamp, Server, SaveID, DDNet7) " + "VALUES (?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, false)", + pSqlServer->GetPrefix()); + pPrepStmt.reset(pSqlServer->Connection()->prepareStatement(aBuf)); + pPrepStmt->setString(1, pSaveState); + pPrepStmt->setString(2, pData->m_Map); + pPrepStmt->setString(3, Code); + pPrepStmt->setString(4, pData->m_Server); + pPrepStmt->setString(5, aSaveID); + dbg_msg("sql", "%s", aBuf); + pPrepStmt->execute(); + if(str_comp(pData->m_Server, g_Config.m_SvSqlServerName) == 0) + { str_format(pData->m_pResult->m_aMessage, sizeof(pData->m_pResult->m_aMessage), "Team successfully saved by %s. Use '/load %s' to continue", - pData->m_ClientName, pData->m_Code.Str()); - pData->m_pResult->m_Status = CSqlSaveResult::SAVE_SUCCESS; + pData->m_ClientName, Code); } else { - dbg_msg("sql", "ERROR: This save-code already exists"); - pData->m_pResult->m_Status = CSqlSaveResult::SAVE_FAILED; - strcpy(pData->m_pResult->m_aMessage, "This save-code already exists"); + str_format(pData->m_pResult->m_aMessage, sizeof(pData->m_pResult->m_aMessage), + "Team successfully saved by %s. Use '/load %s' on %s to continue", + pData->m_ClientName, Code, pData->m_Server); } + pData->m_pResult->m_Status = CSqlSaveResult::SAVE_SUCCESS; } - catch (sql::SQLException &e) + else { + dbg_msg("sql", "ERROR: This save-code already exists"); pData->m_pResult->m_Status = CSqlSaveResult::SAVE_FAILED; - dbg_msg("sql", "MySQL Error: %s", e.what()); - dbg_msg("sql", "ERROR: Could not save the team"); - - strcpy(pData->m_pResult->m_aMessage, "MySQL Error: Could not save the team"); - pSqlServer->executeSql("unlock tables;"); - return false; + strcpy(pData->m_pResult->m_aMessage, "This save-code already exists"); } } + catch (sql::SQLException &e) + { + pData->m_pResult->m_Status = CSqlSaveResult::SAVE_FAILED; + dbg_msg("sql", "MySQL Error: %s", e.what()); + dbg_msg("sql", "ERROR: Could not save the team"); + + strcpy(pData->m_pResult->m_aMessage, "MySQL Error: Could not save the team"); + pSqlServer->executeSql("unlock tables;"); + return false; + } pSqlServer->executeSql("unlock tables;"); return true; diff --git a/src/game/server/score/sql_score.h b/src/game/server/score/sql_score.h index 00d281bde..e5e16fa4f 100644 --- a/src/game/server/score/sql_score.h +++ b/src/game/server/score/sql_score.h @@ -5,6 +5,7 @@ #define GAME_SERVER_SCORE_SQL_H #include +#include #include "../score.h" @@ -40,7 +41,7 @@ struct CSqlPlayerResult struct CSqlSaveResult { CSqlSaveResult(int PlayerID, IGameController* Controller) : - m_Status(SAVE_SUCCESS), + m_Status(SAVE_FAILED), m_SavedTeam(CSaveTeam(Controller)), m_RequestingPlayer(PlayerID) { @@ -137,8 +138,9 @@ struct CSqlTeamSave : CSqlData char m_ClientName[MAX_NAME_LENGTH]; - sqlstr::CSqlString<128> m_Map; - sqlstr::CSqlString<128> m_Code; + char m_Map[128]; + char m_Code[128]; + char m_aGeneratedCode[128]; char m_Server[5]; }; @@ -188,7 +190,6 @@ class CSqlScore: public IScore { static LOCK ms_FailureFileLock; - static bool Init(CSqlServer* pSqlServer, const CSqlData *pGameData, bool HandleFailure); static bool RandomMapThread(CSqlServer* pSqlServer, const CSqlData *pGameData, bool HandleFailure = false); @@ -218,6 +219,10 @@ class CSqlScore: public IScore CGameContext *m_pGameServer; IServer *m_pServer; + std::vector m_aWordlist; + CPrng m_Prng; + void GeneratePassphrase(char *pBuf, int BufSize); + char m_aMap[64]; char m_aGameUuid[UUID_MAXSTRSIZE];