├── scripts ├── test.js ├── dice │ └── players.json └── __dice.js ├── pawno ├── include │ └── core.inc ├── bin │ ├── quincy.ini │ ├── grep.exe │ ├── pawn.ico │ ├── pawnc.dll │ ├── pawnc.lib │ ├── pawnc.pdb │ ├── ANDANTE.FON │ ├── amxArgs.dll │ ├── amxDGram.dll │ ├── amxFile.dll │ ├── amxFixed.dll │ ├── amxFloat.dll │ ├── amxTime.dll │ ├── callout.dll │ ├── pawncc.exe │ ├── pawncc.pdb │ ├── pawndbg.exe │ ├── pawndbgc.exe │ ├── pawnrun.exe │ ├── quincy.exe │ ├── amxProcess.dll │ ├── amxString.dll │ ├── pawndisasm.exe │ └── pawndisasm.pdb ├── pawn.ico ├── pawnc.dll ├── pawncc.exe ├── pawno.exe ├── lib │ └── pawnc.lib ├── libpawnc.dll ├── scripts │ ├── source_4.amx │ ├── source_59.amx │ ├── source_107.amx │ ├── source_121.amx │ ├── source_130.amx │ ├── source_136.amx │ ├── source_145.amx │ ├── source_153.amx │ ├── source_154.amx │ ├── source_181.amx │ ├── source_196.amx │ ├── source_329.amx │ ├── source_343.amx │ ├── source_359.amx │ ├── source_443.amx │ ├── source_464.amx │ ├── source_514.amx │ ├── source_536.amx │ ├── source_540.amx │ ├── source_552.amx │ ├── source_573.amx │ ├── source_611.amx │ ├── source_667.amx │ ├── source_695.amx │ ├── source_755.amx │ ├── source_781.amx │ ├── source_786.amx │ ├── source_793.amx │ ├── source_806.amx │ ├── source_816.amx │ ├── source_834.amx │ ├── source_836.amx │ ├── source_838.amx │ ├── source_842.amx │ ├── source_848.amx │ ├── source_870.amx │ ├── source_909.amx │ ├── source_914.amx │ ├── source_924.amx │ ├── source_935.amx │ ├── source_963.amx │ ├── source_992.amx │ ├── source_997.amx │ ├── source_130.p │ ├── source_136.p │ ├── source_153.p │ ├── source_181.p │ ├── source_196.p │ ├── source_272 │ ├── source_493 │ ├── source_540.p │ ├── source_552.p │ ├── source_562.p │ ├── source_573.p │ ├── source_59.p │ ├── source_646 │ ├── source_726.p │ ├── source_734.p │ ├── source_786.p │ ├── source_806.p │ ├── source_816.p │ ├── source_836.p │ ├── source_838.p │ ├── source_842.p │ ├── source_909.p │ ├── source_924.p │ ├── source_963.p │ ├── source_992.p │ ├── source_997.p │ ├── source_107.p │ ├── source_343.p │ ├── source_443.p │ ├── source_121.p │ ├── source_145.p │ ├── source_359.p │ ├── source_4.p │ ├── source_536.p │ ├── source_611.p │ ├── source_667.p │ ├── source_935.p │ ├── source_695.p │ ├── source_755.p │ ├── source_781.p │ ├── source_793.p │ ├── source_834.p │ ├── source_848.p │ ├── source_870.p │ ├── source_154.p │ ├── source_329.p │ ├── source_464.p │ ├── source_514.p │ └── source_914.p ├── settings.ini └── xml │ ├── pawndoc.css │ └── pawndoc.xsl ├── random.js ├── logger.js ├── lists.js ├── gist.js ├── wiki_cleanup.js ├── file_downloader.js ├── async_eval.js ├── pawn.js ├── vk_bot.js ├── node-amx ├── amxheader.js └── amx.js ├── vk_api.js └── bot.js /scripts/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | return args.toString(); -------------------------------------------------------------------------------- /pawno/include/core.inc: -------------------------------------------------------------------------------- 1 | #pragma library Core 2 | 3 | native say(const text[]); -------------------------------------------------------------------------------- /pawno/bin/quincy.ini: -------------------------------------------------------------------------------- 1 | [Pawn] 2 | PadURL=http://www.compuphase.com/padfiles/pawn.xml 3 | -------------------------------------------------------------------------------- /pawno/pawn.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/pawn.ico -------------------------------------------------------------------------------- /pawno/pawnc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/pawnc.dll -------------------------------------------------------------------------------- /pawno/pawncc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/pawncc.exe -------------------------------------------------------------------------------- /pawno/pawno.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/pawno.exe -------------------------------------------------------------------------------- /pawno/bin/grep.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/grep.exe -------------------------------------------------------------------------------- /pawno/bin/pawn.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawn.ico -------------------------------------------------------------------------------- /pawno/bin/pawnc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawnc.dll -------------------------------------------------------------------------------- /pawno/bin/pawnc.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawnc.lib -------------------------------------------------------------------------------- /pawno/bin/pawnc.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawnc.pdb -------------------------------------------------------------------------------- /pawno/lib/pawnc.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/lib/pawnc.lib -------------------------------------------------------------------------------- /pawno/libpawnc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/libpawnc.dll -------------------------------------------------------------------------------- /pawno/bin/ANDANTE.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/ANDANTE.FON -------------------------------------------------------------------------------- /pawno/bin/amxArgs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxArgs.dll -------------------------------------------------------------------------------- /pawno/bin/amxDGram.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxDGram.dll -------------------------------------------------------------------------------- /pawno/bin/amxFile.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxFile.dll -------------------------------------------------------------------------------- /pawno/bin/amxFixed.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxFixed.dll -------------------------------------------------------------------------------- /pawno/bin/amxFloat.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxFloat.dll -------------------------------------------------------------------------------- /pawno/bin/amxTime.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxTime.dll -------------------------------------------------------------------------------- /pawno/bin/callout.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/callout.dll -------------------------------------------------------------------------------- /pawno/bin/pawncc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawncc.exe -------------------------------------------------------------------------------- /pawno/bin/pawncc.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawncc.pdb -------------------------------------------------------------------------------- /pawno/bin/pawndbg.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawndbg.exe -------------------------------------------------------------------------------- /pawno/bin/pawndbgc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawndbgc.exe -------------------------------------------------------------------------------- /pawno/bin/pawnrun.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawnrun.exe -------------------------------------------------------------------------------- /pawno/bin/quincy.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/quincy.exe -------------------------------------------------------------------------------- /pawno/bin/amxProcess.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxProcess.dll -------------------------------------------------------------------------------- /pawno/bin/amxString.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/amxString.dll -------------------------------------------------------------------------------- /pawno/bin/pawndisasm.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawndisasm.exe -------------------------------------------------------------------------------- /pawno/bin/pawndisasm.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/bin/pawndisasm.pdb -------------------------------------------------------------------------------- /pawno/scripts/source_4.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_4.amx -------------------------------------------------------------------------------- /pawno/scripts/source_59.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_59.amx -------------------------------------------------------------------------------- /pawno/scripts/source_107.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_107.amx -------------------------------------------------------------------------------- /pawno/scripts/source_121.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_121.amx -------------------------------------------------------------------------------- /pawno/scripts/source_130.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_130.amx -------------------------------------------------------------------------------- /pawno/scripts/source_136.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_136.amx -------------------------------------------------------------------------------- /pawno/scripts/source_145.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_145.amx -------------------------------------------------------------------------------- /pawno/scripts/source_153.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_153.amx -------------------------------------------------------------------------------- /pawno/scripts/source_154.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_154.amx -------------------------------------------------------------------------------- /pawno/scripts/source_181.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_181.amx -------------------------------------------------------------------------------- /pawno/scripts/source_196.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_196.amx -------------------------------------------------------------------------------- /pawno/scripts/source_329.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_329.amx -------------------------------------------------------------------------------- /pawno/scripts/source_343.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_343.amx -------------------------------------------------------------------------------- /pawno/scripts/source_359.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_359.amx -------------------------------------------------------------------------------- /pawno/scripts/source_443.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_443.amx -------------------------------------------------------------------------------- /pawno/scripts/source_464.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_464.amx -------------------------------------------------------------------------------- /pawno/scripts/source_514.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_514.amx -------------------------------------------------------------------------------- /pawno/scripts/source_536.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_536.amx -------------------------------------------------------------------------------- /pawno/scripts/source_540.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_540.amx -------------------------------------------------------------------------------- /pawno/scripts/source_552.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_552.amx -------------------------------------------------------------------------------- /pawno/scripts/source_573.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_573.amx -------------------------------------------------------------------------------- /pawno/scripts/source_611.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_611.amx -------------------------------------------------------------------------------- /pawno/scripts/source_667.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_667.amx -------------------------------------------------------------------------------- /pawno/scripts/source_695.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_695.amx -------------------------------------------------------------------------------- /pawno/scripts/source_755.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_755.amx -------------------------------------------------------------------------------- /pawno/scripts/source_781.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_781.amx -------------------------------------------------------------------------------- /pawno/scripts/source_786.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_786.amx -------------------------------------------------------------------------------- /pawno/scripts/source_793.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_793.amx -------------------------------------------------------------------------------- /pawno/scripts/source_806.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_806.amx -------------------------------------------------------------------------------- /pawno/scripts/source_816.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_816.amx -------------------------------------------------------------------------------- /pawno/scripts/source_834.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_834.amx -------------------------------------------------------------------------------- /pawno/scripts/source_836.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_836.amx -------------------------------------------------------------------------------- /pawno/scripts/source_838.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_838.amx -------------------------------------------------------------------------------- /pawno/scripts/source_842.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_842.amx -------------------------------------------------------------------------------- /pawno/scripts/source_848.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_848.amx -------------------------------------------------------------------------------- /pawno/scripts/source_870.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_870.amx -------------------------------------------------------------------------------- /pawno/scripts/source_909.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_909.amx -------------------------------------------------------------------------------- /pawno/scripts/source_914.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_914.amx -------------------------------------------------------------------------------- /pawno/scripts/source_924.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_924.amx -------------------------------------------------------------------------------- /pawno/scripts/source_935.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_935.amx -------------------------------------------------------------------------------- /pawno/scripts/source_963.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_963.amx -------------------------------------------------------------------------------- /pawno/scripts/source_992.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_992.amx -------------------------------------------------------------------------------- /pawno/scripts/source_997.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycckue-Bnepeg/vk_bot/master/pawno/scripts/source_997.amx -------------------------------------------------------------------------------- /scripts/dice/players.json: -------------------------------------------------------------------------------- 1 | {"1526362":{"balance":952},"8512556":{"balance":525},"25125566":{"balance":24},"86711420":{"balance":100,"game":0,"bet":0},"116663568":{"balance":10000409,"game":0,"bet":0}} -------------------------------------------------------------------------------- /pawno/scripts/source_130.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_136.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_153.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_181.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_196.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_272: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_493: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_540.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_552.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_562.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue; 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_573.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_59.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_646: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_726.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue; 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_734.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue; 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_786.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_806.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_816.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_836.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_838.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_842.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_909.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_924.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_963.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_992.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_997.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | printf("Say %s fuckgg %d", strHello, intValue); 9 | } -------------------------------------------------------------------------------- /pawno/scripts/source_107.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | say("hello!"); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_343.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | say("hello!"); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_443.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | say("hello!"); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_121.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_145.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_359.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_4.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_536.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_611.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_667.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /pawno/scripts/source_935.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new unused = 0x100; 9 | printf("Say %s fuckgg %d", strHello, intValue); 10 | return intValue; 11 | } -------------------------------------------------------------------------------- /random.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | random_element: function(array) { 5 | return array[this.random(0, array.length - 1)]; 6 | }, 7 | random: function(min, max) { 8 | return Math.round(min + Math.random() * (max - min)); 9 | } 10 | }; -------------------------------------------------------------------------------- /pawno/settings.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | FileAssoc=1 3 | [Display] 4 | WindowMax=1 5 | WindowX=634 6 | WindowY=316 7 | WindowW=790 8 | WindowH=485 9 | Splitter=339 10 | Font_Name=Courier New 11 | Font_Size=10 12 | ShowFuncList=1 13 | [RunOpts] 14 | CopyDir=\ 15 | ExeFile=pawncc.exe 16 | Params=-r -w 203 17 | 18 | -------------------------------------------------------------------------------- /pawno/scripts/source_695.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, fuckgg); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_755.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, fuckgg); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_781.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, fuckgg); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_793.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, fuckgg); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_834.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, fuckgg); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_848.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, fuckgg); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_870.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, 1337); // Say Hello! fuckgg 0x7F wow 1337 11 | return intValue; 12 | } -------------------------------------------------------------------------------- /pawno/scripts/source_154.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, 1337); // Say Hello! fuckgg 0x7F wow 1337 11 | test(intValue); 12 | return intValue; 13 | } -------------------------------------------------------------------------------- /pawno/scripts/source_329.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, 1337); // Say Hello! fuckgg 0x7F wow 1337 11 | test(intValue, 1337, strHello); 12 | return intValue; 13 | } -------------------------------------------------------------------------------- /pawno/scripts/source_464.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, 1337); // Say Hello! fuckgg 0x7F wow 1337 11 | test(intValue, 1337, strHello); 12 | return intValue; 13 | } -------------------------------------------------------------------------------- /pawno/scripts/source_514.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, 1337); // Say Hello! fuckgg 0x7F wow 1337 11 | test(intValue, 1337, strHello); 12 | return intValue; 13 | } -------------------------------------------------------------------------------- /pawno/scripts/source_914.p: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | forward main(); 4 | 5 | public main() { 6 | new strHello[] = "Hello!"; 7 | new intValue = 0x7F; 8 | new fuckgg = 1337; 9 | new unused = 0x100; 10 | printf("Say %s fuckgg %x wow %d", strHello, intValue, 1337); // Say Hello! fuckgg 0x7F wow 1337 11 | test(intValue, 1337, strHello); 12 | return intValue; 13 | } -------------------------------------------------------------------------------- /logger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const winston = require('winston'); 4 | 5 | module.exports = new winston.Logger({ 6 | transports: [ 7 | new winston.transports.File({ 8 | name: 'info-file', 9 | filename: 'vk-bot.log', 10 | level: 'info', 11 | timestamp: true, 12 | json: false 13 | }), 14 | new winston.transports.Console({ 15 | name: 'info-console', 16 | level: 'error', 17 | timestamp: true, 18 | colorize: true 19 | }) 20 | ] 21 | }); -------------------------------------------------------------------------------- /lists.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const randlib = require('./random'); 4 | 5 | module.exports = class List { 6 | constructor(users) { 7 | this.users = users; 8 | } 9 | 10 | get() { 11 | const index = randlib.random(0, this.users.length - 1); 12 | const user = this.users[index]; 13 | this.users = this.users.slice(0, index).concat(this.users.slice(index + 1, this.users.length)); 14 | return user; 15 | } 16 | 17 | getOnlyName() { 18 | const user = this.get(); 19 | return `${user.first_name} ${user.last_name}`; 20 | } 21 | }; -------------------------------------------------------------------------------- /gist.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const request = require('request'); 4 | const url = require('url'); 5 | 6 | function get_code_from_gist(href, callback) { 7 | const link = url.parse(href); 8 | 9 | if (link.host !== 'gist.github.com') 10 | return callback(new Error(`Неверная ссылка.`)); 11 | 12 | request({ 13 | uri: `https://api.github.com/gists/${link.path.split('/').pop()}`, 14 | headers: { 15 | 'User-Agent': 'fuckgg' 16 | } 17 | }, (error, response, body) => { 18 | if (error) 19 | return callback(new Error(`Не удалось получить исходный текст.`)); 20 | 21 | const result = JSON.parse(body); 22 | 23 | if (result.files === undefined || Object.keys(result.files).length === 0) 24 | return callback(new Error(`Не удалось получить исходный текст.`)); 25 | 26 | const file = Object.keys(result.files)[0]; 27 | callback(null, result.files[file].content); 28 | }); 29 | } 30 | 31 | module.exports = get_code_from_gist; -------------------------------------------------------------------------------- /wiki_cleanup.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function cleanup(text) { 4 | const ZNACHENIE_ZNAESH_EBANUTIY_CUSOK = /====\s?Значение\s?====/; 5 | 6 | const index = text.search(ZNACHENIE_ZNAESH_EBANUTIY_CUSOK); 7 | if (index === -1) 8 | return null; 9 | 10 | const OBRUBOK = text.substring(text.indexOf('\n', index)); 11 | const ESHE_OBRUBOK_EVANIY = OBRUBOK.substring(0, OBRUBOK.indexOf('====')); 12 | 13 | return ESHE_OBRUBOK_EVANIY.split('#') 14 | .slice(1) 15 | .map(value => value.slice(0, value.search('{{пример')) 16 | .trim() 17 | .replace(/\[\[(([^\]]+\|)?([^\]]+|[^\]]+))\]\]/g, '$3') 18 | .replace(/\{\{=\|([^\{\}]+)\}\}/g, 'то же, что и $1') 19 | .replace(/\{\{([^\{\}]+)\|(ru|lang=ru)\}\}/g, '$1') 20 | .replace(/\{\{(помета|выдел)\|([^\{\}]+)\}\}/g, '$2') 21 | .replace(/\{\{свойство\|(((.+)\|(.+))|(.+))\}\}/g, 'свойство от прилагательного $5$3;$4') 22 | .replace(/\{\{([^\{\}]+)\}\}/g, '$1')); 23 | } -------------------------------------------------------------------------------- /file_downloader.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const http = require('http'); 3 | 4 | module.exports = function(url, dest, cb) { 5 | const file = fs.createWriteStream(dest); 6 | const request = http.get(url, function(response) { 7 | 8 | // check if response is success 9 | if (response.statusCode !== 200) { 10 | return cb('Response status was ' + response.statusCode); 11 | } 12 | 13 | response.pipe(file); 14 | 15 | file.on('finish', function() { 16 | file.close(cb); // close() is async, call cb after close completes. 17 | }); 18 | }); 19 | 20 | // check for request error too 21 | request.on('error', function (err) { 22 | fs.unlink(dest); 23 | 24 | if (cb) { 25 | return cb(err.message); 26 | } 27 | }); 28 | 29 | file.on('error', function(err) { // Handle errors 30 | fs.unlink(dest); // Delete the file async. (But we don't check the result) 31 | 32 | if (cb) { 33 | return cb(err.message); 34 | } 35 | }); 36 | }; -------------------------------------------------------------------------------- /async_eval.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const vm = require('vm'); 4 | 5 | const query = process.argv[2] || ''; 6 | const args = (process.argv[3] !== undefined) ? JSON.parse(process.argv[3]) : new Array(); 7 | const fixedCode = query.replace(/"/g, '"').replace(/
/g, '\n').replace(/«/g, '<<').replace(/»/g, '>>'); 8 | 9 | /*const context = { 10 | hex: value => `0x${value.toString(16)}`, 11 | bin: value => value.toString(2), 12 | args: args 13 | };*/ 14 | 15 | let context = Math; 16 | context.hex = value => `0x${value.toString(16)}`; 17 | context.bin = value => value.toString(2); 18 | context.args = args; 19 | 20 | const options = { 21 | timeout: 5000 22 | }; 23 | 24 | try { 25 | const script = new vm.Script(`'use strict'; (function() { ${fixedCode} })();`, options); 26 | const result = script.runInNewContext(context, options); 27 | process.send({ success: true, result: result }); 28 | } catch (error) { 29 | process.send({ success: false, error: error }); 30 | } -------------------------------------------------------------------------------- /pawn.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const AMX = require('./node-amx/amx').AMX; 4 | const randlib = require('./random'); 5 | const fs = require('fs'); 6 | const child_process = require('child_process'); 7 | const EventEmitter = require('events'); 8 | 9 | class Pawn extends EventEmitter { 10 | constructor(code) { 11 | super(); 12 | this.source = code; 13 | } 14 | 15 | compile(callback) { 16 | if (callback == void(0)) 17 | return; 18 | 19 | this.pwnSourceFile = `./pawno/scripts/source_${randlib.random(0, 1000)}`; 20 | 21 | fs.writeFile(`${this.pwnSourceFile}.p`, this.source, error => { 22 | if (error) 23 | return callback(error); 24 | 25 | child_process.exec(`${process.cwd()}/pawno/bin/pawncc ${this.pwnSourceFile}`, (error, stdout, stderr) => { 26 | const errors = stderr.split('\r\n'); 27 | errors.pop(); 28 | 29 | if (error) 30 | return callback(errors); 31 | 32 | return callback(null, errors); 33 | }); 34 | }); 35 | } 36 | 37 | run(callback) { 38 | if (callback == void(0)) 39 | return; 40 | 41 | if (this.pwnSourceFile === undefined) 42 | return callback(new Error(`Сначала нужно скомпилировать код.`)); 43 | 44 | AMX.fromFile(`${this.pwnSourceFile}.amx`, (error, amx) => { 45 | if (error) 46 | return callback(error); 47 | 48 | this.amx = amx; 49 | 50 | this.amx.callback = (pri, stk) => { 51 | const count = stk.readUInt32LE(0); 52 | const args = new Array(); 53 | 54 | //console.log(stk); 55 | 56 | for (let i = 1; i <= (count >> 2); i++) 57 | args.push(stk.readUInt32LE(i << 2)); 58 | 59 | return { 60 | num: 0, 61 | pri: this.emit(this.amx.natives[pri].name, args) 62 | }; 63 | }; 64 | 65 | const main = this.amx.publics.find(element => element.name === 'main'); 66 | 67 | callback(null, this.amx.exec(main.index)); 68 | }); 69 | } 70 | 71 | getString(offset) { 72 | if (this.amx === undefined) 73 | return null; 74 | 75 | const buffer = this.amx.buffer.slice(this.amx.base.dat + offset); 76 | let string = new String(); 77 | 78 | for (let i = 0; i < buffer.length; i += 4) { 79 | const char = buffer.readUInt32LE(i); 80 | 81 | if (char === 0) 82 | break; 83 | 84 | string += String.fromCharCode(char); 85 | } 86 | 87 | return string; 88 | } 89 | } 90 | 91 | module.exports = Pawn; -------------------------------------------------------------------------------- /scripts/__dice.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const randlib = require('../random'); 4 | const fs = require('fs'); 5 | 6 | const database = { 7 | filename: './scripts/dice/players.json', 8 | __base: new Object(), 9 | 10 | open: function() { 11 | this.__base = JSON.parse(fs.readFileSync(this.filename)); 12 | }, 13 | 14 | set: function(user, key, value) { 15 | if (!this.__base.hasOwnProperty(user)) 16 | this.__base[user] = new Object(); 17 | 18 | this.__base[user][key] = value; 19 | this.save(); 20 | }, 21 | 22 | get: function(user, key) { 23 | if (this.__base.hasOwnProperty(user)) 24 | return this.__base[user][key]; 25 | else 26 | return null; 27 | }, 28 | 29 | save: function() { 30 | fs.writeFileSync(this.filename, JSON.stringify(this.__base)); 31 | } 32 | }; 33 | 34 | database.open(); 35 | 36 | module.exports = { 37 | getTop: function() { 38 | return Object.keys(database.__base).sort((a, b) => database.__base[a].balance - database.__base[b].balance).slice(0, 5).reverse(); 39 | }, 40 | 41 | getBalance: function(player) { 42 | return database.get(player, 'balance'); 43 | }, 44 | 45 | setBalance: function(player, balance) { 46 | database.set(player, 'balance', balance); 47 | }, 48 | 49 | inc: function(player, count) { 50 | this.setBalance(player, this.getBalance(player) + count); 51 | }, 52 | 53 | dec: function(player, count) { 54 | this.inc(player, -count); 55 | }, 56 | 57 | reset: function(player) { 58 | this.setBalance(player, 100); 59 | }, 60 | 61 | playerIsFree: function(player) { 62 | const game = database.get(from, 'game'); 63 | return (game === undefined || game === 0); 64 | }, 65 | 66 | bet: function(from, to, bet) { 67 | const balanceFirst = this.getBalance(from); 68 | const balanceTwo = this.getBalance(to); 69 | 70 | if (balanceFirst == null) 71 | return { success: false, reason: 'Вы не зарегистрированны.' }; 72 | 73 | if (from === to) 74 | return { success: false, reason: 'Нельзя играть с самим собой ...' }; 75 | 76 | if (balanceTwo == null) 77 | return { success: false, reason: 'Оппонент не зарегистрирован.' }; 78 | 79 | if (bet < 10) 80 | return { success: false, reason: 'Ставки от 10$!' }; 81 | 82 | if (balanceFirst < bet) 83 | return { success: false, reason: 'У вас недостаточно денег на счету.' }; 84 | if (balanceTwo < bet) 85 | return { success: false, reason: 'У оппонента недостаточно денег на счету.' }; 86 | 87 | if (!this.playerIsFree(from) || !this.playerIsFree(to)) 88 | return { success: false, reason: 'В данный момент невозможно вызывать этого игрока.' }; 89 | 90 | database.set(from, 'game', to); 91 | database.set(to, 'game', from); 92 | database.set(from, 'bet', bet); 93 | database.set(to, 'bet', bet); 94 | 95 | return { success: true }; 96 | }, 97 | 98 | play: function(player) { 99 | const opponent = database.get(player, 'game'); 100 | const bet = database.get(player, 'bet'); 101 | 102 | if (opponent === null) 103 | return { success: false, reason: 'Вы не зарегистрированны.' }; 104 | 105 | if (opponent === undefined || opponent === 0) 106 | return { success: false, reason: 'К вам нет встречных предложений.' }; 107 | 108 | const winner = randlib.random(0, 1); 109 | 110 | if (winner) { 111 | this.inc(player, bet); 112 | this.dec(opponent, bet); 113 | } else { 114 | this.dec(player, bet); 115 | this.inc(opponent, bet); 116 | } 117 | 118 | this.clear(player); 119 | 120 | const balance = this.getBalance(player); 121 | 122 | return { success: true, winner: winner, balance: balance }; 123 | }, 124 | 125 | decline: function(player) { 126 | const opponent = database.get(player, 'game'); 127 | 128 | if (opponent === null) 129 | return { success: false, reason: 'Вы не зарегистрированны.' }; 130 | 131 | if (opponent === undefined || opponent === 0) 132 | return { success: false, reason: 'Вы не предлагали никому игру.' }; 133 | 134 | this.clear(player); 135 | 136 | return { success: true }; 137 | }, 138 | 139 | clear: function(player) { 140 | const opponent = database.get(player, 'game'); 141 | 142 | database.set(player, 'game', 0); 143 | database.set(opponent, 'game', 0); 144 | database.set(player, 'bet', 0); 145 | database.set(opponent, 'bet', 0); 146 | } 147 | }; -------------------------------------------------------------------------------- /pawno/xml/pawndoc.css: -------------------------------------------------------------------------------- 1 | /* Version: $Id: pawndoc.css 3845 2007-11-16 14:41:29Z thiadmer $ */ 2 | 3 | BODY 4 | { 5 | FONT-FAMILY: "Verdana", sans-serif; 6 | FONT-SIZE: x-small; 7 | } 8 | 9 | CODE 10 | { 11 | FONT-SIZE: x-small; 12 | } 13 | 14 | DL 15 | { 16 | MARGIN-LEFT: 4em; 17 | DISPLAY: compact 18 | } 19 | 20 | DT 21 | { 22 | FONT-WEIGHT: bold 23 | } 24 | 25 | A:link 26 | { 27 | COLOR: #4e4887 28 | } 29 | 30 | A:visited 31 | { 32 | COLOR: #8080c8 33 | } 34 | 35 | A:active 36 | { 37 | COLOR: #f16043 38 | } 39 | 40 | A:hover 41 | { 42 | COLOR: #f16043 43 | } 44 | 45 | P 46 | { 47 | MARGIN-BOTTOM: 0.5em; 48 | MARGIN-TOP: 0.5em; 49 | MARGIN-LEFT: 4em 50 | } 51 | 52 | P.noindent 53 | { 54 | MARGIN-LEFT: 0em 55 | } 56 | 57 | P.syntax 58 | { 59 | FONT-WEIGHT: bold 60 | } 61 | 62 | HR.para 63 | { 64 | HEIGHT: 0; 65 | BORDER: 0; 66 | COLOR: transparent; 67 | BACKGROUND-COLOR: transparent; 68 | MARGIN-TOP: 0.5em; 69 | MARGIN-BOTTOM: 0; 70 | } 71 | 72 | XMP 73 | { 74 | BACKGROUND-COLOR: #ddeeff; 75 | FONT-SIZE: x-small; 76 | MARGIN: 1em 77 | } 78 | 79 | PRE 80 | { 81 | BACKGROUND-COLOR: #ddeeff; 82 | FONT-SIZE: x-small; 83 | MARGIN: 1em 84 | } 85 | 86 | TABLE 87 | { 88 | BORDER-BOTTOM: medium none; 89 | BORDER-LEFT: medium none; 90 | BORDER-RIGHT: medium none; 91 | BORDER-TOP: medium none 92 | } 93 | 94 | TABLE.param 95 | { 96 | BACKGROUND-COLOR: #ddeeff; 97 | } 98 | 99 | TABLE.transition 100 | { 101 | BACKGROUND-COLOR: #ddeeff; 102 | } 103 | 104 | TD 105 | { 106 | BACKGROUND-COLOR: #ddeeff; 107 | BORDER-BOTTOM: medium none; 108 | BORDER-LEFT: medium none; 109 | BORDER-RIGHT: medium none; 110 | BORDER-TOP: medium none; 111 | FONT-SIZE: x-small; 112 | MARGIN: 2px; 113 | PADDING-BOTTOM: 2px; 114 | PADDING-LEFT: 2px; 115 | PADDING-RIGHT: 2px; 116 | PADDING-TOP: 2px; 117 | TEXT-ALIGN: left 118 | } 119 | 120 | TD.header 121 | { 122 | BACKGROUND-COLOR: transparent; 123 | FONT-WEIGHT: bold; 124 | COLOR: #4e4887; 125 | WIDTH: 3.3em; 126 | PADDING-LEFT: 0px; 127 | MARGIN-BOTTOM: 0.5em 128 | } 129 | 130 | TD.inline 131 | { 132 | BACKGROUND-COLOR: transparent 133 | } 134 | 135 | TD.param 136 | { 137 | FONT-WEIGHT: bold; 138 | FONT-STYLE: italic; 139 | PADDING-RIGHT: 20px; 140 | } 141 | 142 | TD.transition 143 | { 144 | PADDING-RIGHT: 10px; 145 | } 146 | 147 | TH 148 | { 149 | BACKGROUND-COLOR: #336699; 150 | COLOR: #ddeeff; 151 | BORDER-BOTTOM: medium none; 152 | BORDER-LEFT: medium none; 153 | BORDER-RIGHT: medium none; 154 | BORDER-TOP: medium none; 155 | FONT-SIZE: x-small; 156 | MARGIN: 2px; 157 | PADDING-BOTTOM: 2px; 158 | PADDING-LEFT: 4px; 159 | PADDING-RIGHT: 4px; 160 | PADDING-TOP: 2px; 161 | TEXT-ALIGN: left 162 | } 163 | 164 | UL 165 | { 166 | MARGIN-TOP: 0.5em; 167 | /* MARGIN-LEFT: 4em */ 168 | } 169 | 170 | LI.referrer 171 | { 172 | DISPLAY: inline; 173 | PADDING-RIGHT: 8px 174 | } 175 | 176 | LI.dependency 177 | { 178 | DISPLAY: inline; 179 | PADDING-RIGHT: 8px 180 | } 181 | 182 | LI.seealso 183 | { 184 | DISPLAY: inline; 185 | PADDING-RIGHT: 8px 186 | } 187 | 188 | LI.attribute 189 | { 190 | DISPLAY: inline; 191 | PADDING-RIGHT: 8px 192 | } 193 | 194 | OL 195 | { 196 | MARGIN-TOP: 0.5em; 197 | /* MARGIN-LEFT: 4em */ 198 | } 199 | 200 | SPAN.paraminfo { 201 | FONT-WEIGHT:Bold; 202 | COLOR: #336699; 203 | } 204 | 205 | H1 206 | { 207 | COLOR: #336699; 208 | FONT-SIZE: x-large; 209 | MARGIN-BOTTOM: 0.5em; 210 | MARGIN-TOP: 1em; 211 | PADDING-LEFT: 4px 212 | } 213 | 214 | H2 215 | { 216 | BORDER-RIGHT: #4e4887 8px solid; 217 | BORDER-TOP: #4e4887 2px solid; 218 | COLOR: #4e4887; 219 | FONT-SIZE: medium-large; 220 | MARGIN-BOTTOM: 0.5em; 221 | MARGIN-TOP: 1em; 222 | } 223 | 224 | H2.general 225 | { 226 | BORDER: none; 227 | } 228 | 229 | H3 230 | { 231 | COLOR: #4e4887; 232 | FONT-SIZE: x-small; 233 | MARGIN-BOTTOM: 0.5em 234 | } 235 | 236 | H4 237 | { 238 | COLOR: #4e4887; 239 | FONT-SIZE: x-small; 240 | FONT-STYLE: italic; 241 | MARGIN-BOTTOM: 0.5em 242 | } 243 | 244 | H5 245 | { 246 | COLOR: #4e4887; 247 | FONT-SIZE: xx-small; 248 | MARGIN-BOTTOM: 0.5em 249 | } 250 | 251 | H6 252 | { 253 | COLOR: #4e4887; 254 | FONT-SIZE: xx-small; 255 | FONT-STYLE: italic; 256 | MARGIN-BOTTOM: 0.5em 257 | } 258 | -------------------------------------------------------------------------------- /vk_bot.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const request = require('request'); 4 | const EventEmitter = require('events'); 5 | const VKAPIWrapper = require('./vk_api.js'); 6 | const logger = require('./logger'); 7 | const fs = require('fs'); 8 | 9 | const COMMAND_PATTERN = /^@(\w+)(\((.*)\))?(\s(.*))?/; 10 | 11 | class VKBot extends EventEmitter { 12 | constructor(account) { 13 | super(); 14 | this.vk = new VKAPIWrapper(account); 15 | this.vk.auth(this.onAuth.bind(this)); 16 | this.commands = new Map(); 17 | this.vars = new Object(); 18 | } 19 | 20 | onAuth(error, result) { 21 | if (!error) { 22 | logger.info('Success auth. Bot id %d', result.user_id); 23 | this.bot_id = result.user_id; 24 | this.vk.longPoll((event, args) => { 25 | if (event !== 4) 26 | return; 27 | else this.onNewMessage({ 28 | id: args[0], 29 | flags: args[1], 30 | from: args[2], 31 | timestamp: args[3], 32 | subject: args[4], 33 | text: args[5], 34 | attachments: args[6] 35 | }); 36 | }); 37 | 38 | this.on('help', function(info, args, query) { 39 | logger.info('help request from %d', info.peer, query); 40 | 41 | const separator = '\n--------------------------------\n'; 42 | 43 | if (query !== undefined) { 44 | if (!this.commands.has(query)) 45 | return this.response(info.peer, 'Такой команды не существует.'); 46 | 47 | const command = this.commands.get(query); 48 | let response = `Описание команды @${query}:`; 49 | 50 | response += `${separator}@${command.syntax} — ${command.description}`; 51 | if (command.args) 52 | response += `${separator}Параметры:\n${command.args.map(arg => `${arg.name} — ${arg.description}`).join('\n')}`; 53 | if (command.examples) 54 | response += `${separator}Примеры:\n${command.examples.join('\n')}`; 55 | 56 | this.response(info.peer, response, null, [ info.message ]); 57 | } else { 58 | let response = 'Список команд:\nДля более подробной информации введите @help command.\n'; 59 | this.commands.forEach((value, key) => { 60 | response += `${separator}@${value.syntax} — ${value.description}`; 61 | }); 62 | this.response(info.peer, response); 63 | } 64 | }); 65 | } 66 | } 67 | 68 | onNewMessage(message) { 69 | /*if (message.from === this.bot_id || (message.from >= 2000000000 && message.attachments['from'] === this.bot_id)) 70 | return;*/ 71 | 72 | const text = message.text; 73 | const matches = text.match(COMMAND_PATTERN); 74 | 75 | if (matches === null) 76 | return; 77 | 78 | const command = matches[1]; 79 | let command_args = matches[3]; 80 | const query = matches[5]; 81 | 82 | const sender = (message.from >= 2e9) ? message.attachments['from'] : message.from; 83 | const chat_id = message.from; 84 | 85 | if (command_args !== undefined) 86 | command_args = command_args.split(',').map(string => string.trim()); 87 | else 88 | command_args = new Array(); 89 | 90 | logger.info('recieved command "%s" from %d (sender %d): %s', command, chat_id, sender, query, command_args); 91 | 92 | this.emit(command, { peer: chat_id, sender: sender, message: message.id }, command_args, query); 93 | } 94 | 95 | response(to, message, attachments, forward_messages) { 96 | logger.info('response to %d with message "%s"', to, message, attachments, forward_messages); 97 | 98 | this.vk.call('messages.send', { 99 | peer_id: to, 100 | message: message, 101 | attachment: (attachments != void(0)) ? attachments.join(',') : 0, 102 | forward_messages: (forward_messages != void(0)) ? forward_messages.join(',') : 0 103 | }, (err) => (err != void(0)) ? logger.error(err) : 0); 104 | } 105 | 106 | getListOfChatUsers(chat, callback) { 107 | if (callback === undefined) 108 | return; 109 | 110 | this.vk.call('messages.getChat', { 111 | chat_id: chat - 2e9, 112 | fields: 'first_name, last_name' 113 | }, (error, result) => { 114 | if (error != void(0)) { 115 | logger.warn('cannot get info about chat_id %d', chat - 2e9); 116 | return callback(error); 117 | } 118 | callback(null, result.users); 119 | }); 120 | } 121 | 122 | uploadImage(image, callback) { 123 | if (callback === undefined) 124 | return; 125 | 126 | this.vk.call('photos.getMessagesUploadServer', {}, (error, result) => { 127 | if (error) { 128 | logger.warn('cannot get upload server', error); 129 | return callback(error); 130 | } 131 | 132 | logger.info('start uploading to', result); 133 | 134 | request.post({ 135 | uri: result.upload_url, 136 | formData: { 137 | photo: fs.createReadStream(image) 138 | } 139 | }, (error, response, body) => { 140 | if (error || response.statusCode !== 200) { 141 | logger.warn('cannot upload image', error, response.statusCode); 142 | return callback(error); 143 | } 144 | 145 | const result = JSON.parse(body); 146 | 147 | logger.info('success upload photo', result); 148 | 149 | this.vk.call('photos.saveMessagesPhoto', result, (error, result) => { 150 | if (error) { 151 | logger.warn('cannot save message photo', error); 152 | return callback(error); 153 | } 154 | 155 | logger.info('success save photo', result); 156 | return callback(null, result); 157 | }); 158 | }); 159 | }); 160 | } 161 | 162 | resolveScreenName(name, callback) { 163 | if (callback === undefined) 164 | return; 165 | 166 | this.vk.call('utils.resolveScreenName', { screen_name: name }, callback); 167 | } 168 | 169 | setDescriptionForCmd(command, description) { 170 | this.commands.set(command, description); 171 | } 172 | } 173 | 174 | module.exports = VKBot; -------------------------------------------------------------------------------- /node-amx/amxheader.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Kester Everts 2012 3 | */ 4 | 5 | ////typedef struct tagAMX_HEADER { 6 | // 00 int32_t size PACKED; /* size of the "file" */ 7 | // 04 uint16_t magic PACKED; /* signature */ 8 | // 06 char file_version; /* file format version */ 9 | // 07 char amx_version; /* required version of the AMX */ 10 | // 08 int16_t flags PACKED; 11 | // 10 int16_t defsize PACKED; /* size of a definition record */ 12 | // 12 int32_t cod PACKED; /* initial value of COD - code block */ 13 | // 16 int32_t dat PACKED; /* initial value of DAT - data block */ 14 | // 20 int32_t hea PACKED; /* initial value of HEA - start of the heap */ 15 | // 24 int32_t stp PACKED; /* initial value of STP - stack top */ 16 | // 28 int32_t cip PACKED; /* initial value of CIP - the instruction pointer */ 17 | // 32 int32_t publics PACKED; /* offset to the "public functions" table */ 18 | // 36 int32_t natives PACKED; /* offset to the "native functions" table */ 19 | // 40 int32_t libraries PACKED; /* offset to the table of libraries */ 20 | // 44 int32_t pubvars PACKED; /* the "public variables" table */ 21 | // 48 int32_t tags PACKED; /* the "public tagnames" table */ 22 | // 52 int32_t nametable PACKED; /* name table */ 23 | //} PACKED AMX_HEADER; 24 | 25 | function AMXHeader(buffer) { 26 | if(!Buffer.isBuffer(buffer)) { 27 | buffer = new Buffer(AMXHeader.BYTE_SIZE); 28 | } 29 | if(buffer.length < AMXHeader.BYTE_SIZE) { 30 | throw new Error("Buffer size is less than AMX header size"); 31 | } 32 | this.buffer = buffer; 33 | } 34 | 35 | AMXHeader.BYTE_SIZE = 56; 36 | 37 | Object.defineProperty(AMXHeader.prototype, "size", { 38 | get: function() { 39 | return this.buffer.readInt32LE(0); 40 | }, 41 | set: function(v) { 42 | this.buffer.writeInt32LE(v, 0); 43 | }, 44 | enumerable: true, configurable: false 45 | }); 46 | 47 | Object.defineProperty(AMXHeader.prototype, "magic", { 48 | get: function() { 49 | return this.buffer.readUInt16LE(4); 50 | }, 51 | set: function(v) { 52 | this.buffer.writeUInt16LE(v, 4); 53 | }, 54 | enumerable: true, configurable: false 55 | }); 56 | 57 | Object.defineProperty(AMXHeader.prototype, "file_version", { 58 | get: function() { 59 | return this.buffer.readInt8(6); 60 | }, 61 | set: function(v) { 62 | this.buffer.writeInt8(v, 6); 63 | }, 64 | enumerable: true, configurable: false 65 | }); 66 | 67 | Object.defineProperty(AMXHeader.prototype, "amx_version", { 68 | get: function() { 69 | return this.buffer.readInt8(7); 70 | }, 71 | set: function(v) { 72 | this.buffer.writeInt8(v, 7); 73 | }, 74 | enumerable: true, configurable: false 75 | }); 76 | 77 | Object.defineProperty(AMXHeader.prototype, "flags", { 78 | get: function() { 79 | return this.buffer.readInt16LE(8); 80 | }, 81 | set: function(v) { 82 | this.buffer.writeInt16LE(v, 8); 83 | }, 84 | enumerable: true, configurable: false 85 | }); 86 | 87 | Object.defineProperty(AMXHeader.prototype, "defsize", { 88 | get: function() { 89 | return this.buffer.readInt16LE(10); 90 | }, 91 | set: function(v) { 92 | this.buffer.writeInt16LE(v, 10); 93 | }, 94 | enumerable: true, configurable: false 95 | }); 96 | 97 | Object.defineProperty(AMXHeader.prototype, "cod", { 98 | get: function() { 99 | return this.buffer.readInt32LE(12); 100 | }, 101 | set: function(v) { 102 | this.buffer.writeInt32LE(v, 12); 103 | }, 104 | enumerable: true, configurable: false 105 | }); 106 | 107 | Object.defineProperty(AMXHeader.prototype, "dat", { 108 | get: function() { 109 | return this.buffer.readInt32LE(16); 110 | }, 111 | set: function(v) { 112 | this.buffer.writeInt32LE(v, 16); 113 | }, 114 | enumerable: true, configurable: false 115 | }); 116 | 117 | Object.defineProperty(AMXHeader.prototype, "hea", { 118 | get: function() { 119 | return this.buffer.readInt32LE(20); 120 | }, 121 | set: function(v) { 122 | this.buffer.writeInt32LE(v, 20); 123 | }, 124 | enumerable: true, configurable: false 125 | }); 126 | 127 | Object.defineProperty(AMXHeader.prototype, "stp", { 128 | get: function() { 129 | return this.buffer.readInt32LE(24); 130 | }, 131 | set: function(v) { 132 | this.buffer.writeInt32LE(v, 24); 133 | }, 134 | enumerable: true, configurable: false 135 | }); 136 | 137 | Object.defineProperty(AMXHeader.prototype, "cip", { 138 | get: function() { 139 | return this.buffer.readInt32LE(28); 140 | }, 141 | set: function(v) { 142 | this.buffer.writeInt32LE(v, 28); 143 | }, 144 | enumerable: true, configurable: false 145 | }); 146 | 147 | Object.defineProperty(AMXHeader.prototype, "publics", { 148 | get: function() { 149 | return this.buffer.readInt32LE(32); 150 | }, 151 | set: function(v) { 152 | this.buffer.writeInt32LE(v, 32); 153 | }, 154 | enumerable: true, configurable: false 155 | }); 156 | 157 | Object.defineProperty(AMXHeader.prototype, "natives", { 158 | get: function() { 159 | return this.buffer.readInt32LE(36); 160 | }, 161 | set: function(v) { 162 | this.buffer.writeInt32LE(v, 36); 163 | }, 164 | enumerable: true, configurable: false 165 | }); 166 | 167 | Object.defineProperty(AMXHeader.prototype, "libraries", { 168 | get: function() { 169 | return this.buffer.readInt32LE(40); 170 | }, 171 | set: function(v) { 172 | this.buffer.writeInt32LE(v, 40); 173 | }, 174 | enumerable: true, configurable: false 175 | }); 176 | 177 | Object.defineProperty(AMXHeader.prototype, "pubvars", { 178 | get: function() { 179 | return this.buffer.readInt32LE(44); 180 | }, 181 | set: function(v) { 182 | this.buffer.writeInt32LE(v, 44); 183 | }, 184 | enumerable: true, configurable: false 185 | }); 186 | 187 | Object.defineProperty(AMXHeader.prototype, "tags", { 188 | get: function() { 189 | return this.buffer.readInt32LE(0); 190 | }, 191 | set: function(v) { 192 | this.buffer.writeInt32LE(v, 0); 193 | }, 194 | enumerable: true, configurable: false 195 | }); 196 | 197 | Object.defineProperty(AMXHeader.prototype, "nametable", { 198 | get: function() { 199 | return this.buffer.readInt32LE(52); 200 | }, 201 | set: function(v) { 202 | this.buffer.writeInt32LE(v, 52); 203 | }, 204 | enumerable: true, configurable: false 205 | }); 206 | 207 | exports.AMXHeader = AMXHeader; -------------------------------------------------------------------------------- /vk_api.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const request = require('request'); 4 | const base32 = require('thirty-two'); 5 | const notp = require('notp'); 6 | 7 | const winston = require('winston'); 8 | 9 | const logger = new winston.Logger({ 10 | transports: [ 11 | new winston.transports.File({ 12 | name: 'vk-api-file', 13 | filename: 'vk-api-wrapper.log', 14 | level: 'info', 15 | timestamp: true, 16 | json: false 17 | }), 18 | new winston.transports.Console({ 19 | name: 'vk-api-console', 20 | level: 'error', 21 | timestamp: true, 22 | colorize: true 23 | }) 24 | ] 25 | }); 26 | 27 | // https://oauth.vk.com/access_token?client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&v=5.41&grant_type=client_credentials 28 | 29 | const urls = { 30 | auth: 'https://oauth.vk.com/token', 31 | api: 'https://api.vk.com/method/' 32 | }; 33 | 34 | class MethodBuilder { 35 | constructor() { 36 | this.m_method = new Object(); 37 | } 38 | 39 | getMethodInfo() { 40 | return this.m_method; 41 | } 42 | 43 | setMethodName(uri) { 44 | this.m_method.uri = urls.api + uri; 45 | } 46 | 47 | setApiVersion(version) { 48 | this.m_version = version; 49 | } 50 | 51 | setToken(token) { 52 | this.m_token = token; 53 | } 54 | 55 | setCallback(callback) { 56 | this.m_method.callback = callback; 57 | } 58 | 59 | setParams(params) { 60 | this.m_method.params = JSON.parse(JSON.stringify(params)); 61 | this.m_method.params.access_token = this.m_token; 62 | this.m_method.params.v = this.m_version; 63 | } 64 | } 65 | 66 | class VKAPIWrapper { 67 | constructor(settings) { 68 | if (settings === undefined) 69 | throw new Error(`'settings' is undefined`); 70 | if (settings.token !== undefined) 71 | this.setToken(settings.token); 72 | else if (settings.login !== undefined && settings.password !== undefined) 73 | this.setLoginAndPassword(settings.login, settings.password); 74 | else 75 | throw new Error(`Object 'settings' has not a property of login or password or token`); 76 | 77 | if (settings.version !== undefined) 78 | this.setApiVersion(settings.version); 79 | else 80 | this.setApiVersion("5.41"); 81 | 82 | if (settings.key !== undefined) 83 | this.setTotpKey(settings.key); 84 | 85 | this.m_blocked = false; 86 | this.m_fromReg = false; 87 | this.m_queue = new Array(); 88 | this.m_polling = new Object(); 89 | 90 | Array.observe(this.m_queue, this.queueObserver.bind(this)); 91 | } 92 | 93 | auth(onAuth, code) { 94 | if (this.m_login === undefined || this.m_password === undefined && this.m_token !== undefined) { 95 | logger.info('VKAPI auth via token.'); 96 | onAuth(null, this.m_token); 97 | } 98 | else if (this.m_login !== undefined && this.m_password !== undefined) { 99 | logger.info('Auth via login and password. API version %s', this.m_version); 100 | let query = { 101 | grant_type: 'password', 102 | client_id: 2274003, 103 | client_secret: 'hHbZxrka2uZ6jB1inYsH', 104 | username: this.m_login, 105 | password: this.m_password, 106 | '2fa_supported': 1, 107 | v: this.m_version 108 | }; 109 | 110 | if (code !== undefined) 111 | query.code = code; 112 | 113 | request({ uri: urls.auth, qs: query }, (error, response, body) => { 114 | logger.info('response from auth server (code %d).', response.statusCode, query); 115 | logger.info(body); 116 | 117 | if (!error && response.statusCode == 200) { 118 | let res = JSON.parse(body); 119 | this.m_token = res.access_token; 120 | this.m_userid = res.user_id; 121 | 122 | //this.putTokenToReg(this.m_login, this.m_token); 123 | logger.info('success auth'); 124 | onAuth(null, res); 125 | } 126 | else if (response.statusCode == 401) { 127 | let res = JSON.parse(body); 128 | 129 | if (res.error == 'need_validation') { 130 | if (res.validation_type == '2fa_app') { 131 | if (this.m_key !== undefined) { 132 | let code = notp.totp.gen(this.m_key); 133 | logger.warn('need 2fa_app validation. code %s. will try again.', code); 134 | this.auth(onAuth, code); 135 | } 136 | else 137 | onAuth({ error: 'has_not_2fa_key' }); 138 | } 139 | else 140 | onAuth({ error: 'unsupported_validation_type' }); 141 | } 142 | else 143 | onAuth(res); 144 | } 145 | else 146 | onAuth(error); 147 | }); 148 | } 149 | else 150 | throw new Error(`Wrapper has not a login or password`); 151 | } 152 | 153 | setTotpKey(key) { 154 | this.m_key = base32.decode(key); 155 | } 156 | 157 | setApiVersion(version) { 158 | this.m_version = version.toString(); 159 | } 160 | 161 | setLoginAndPassword(login, password) { 162 | //if (login typeof String && password typeof String) 163 | this.m_login = login, this.m_password = password; 164 | //else 165 | //throw new Error(`Variable 'login' or 'password' is not instance of String class`); 166 | } 167 | 168 | setToken(token) { 169 | if (token instanceof String) 170 | this.m_token = token; 171 | else 172 | throw new Error(`'token' is not instance of String class`); 173 | } 174 | 175 | queueObserver(changes) { 176 | if (this.m_blocked == true) 177 | return; 178 | 179 | if (this.m_queue.length > 0) { 180 | let methodInfo = this.m_queue.shift(); 181 | 182 | let wait = () => { 183 | this.m_blocked = true; 184 | setTimeout(() => { 185 | this.m_blocked = false; 186 | this.m_queue.unshift(methodInfo); 187 | }, 1000); 188 | }; 189 | 190 | logger.info('calling api ...'); 191 | 192 | request({ uri: methodInfo.uri, qs: methodInfo.params }, (error, response, body) => { 193 | if (!error) { 194 | if (response.statusCode == 200) { 195 | let result = JSON.parse(body); 196 | 197 | if (!result.error) { 198 | logger.info('success api call', methodInfo.uri, methodInfo.params, result.response); 199 | methodInfo.callback(null, result.response); 200 | } 201 | else if (result.error.error_code == 6) { 202 | logger.info('request limit. wait ...'); 203 | wait(); 204 | } 205 | else { 206 | logger.warn('error from %s', methodInfo.uri, methodInfo.params); 207 | logger.warn(result.error); 208 | methodInfo.callback(result.error); 209 | } 210 | } 211 | else { 212 | logger.warn('server responded with status code %d', response.statusCode); 213 | logger.warn(methodInfo.uri, methodInfo.params); 214 | methodInfo.callback(new Error(`Server responded with status code ${response.statusCode}`)); 215 | } 216 | } 217 | else if (error.code === 'ETIMEDOUT') { 218 | logger.warn('timeout. wait ...'); 219 | wait(); 220 | } 221 | else { 222 | logger.warn(error); 223 | logger.warn(methodInfo.uri, methodInfo.params); 224 | methodInfo.callback(error); 225 | } 226 | }); 227 | } 228 | } 229 | 230 | longPoll(callback) { 231 | this.m_polling = new Object(); 232 | logger.info('getting longpoll server ...'); 233 | this.call('messages.getLongPollServer', { use_ssl: true }, (err, result) => { 234 | if (err !== null) { 235 | logger.error('cannot get longpoll server', err); 236 | return; 237 | } 238 | 239 | this.m_polling.server = result.server; 240 | this.m_polling.ts = result.ts; 241 | this.m_polling.key = result.key; 242 | this.m_polling.callback = callback; 243 | 244 | logger.info('got longpoll server', result); 245 | 246 | this._poll(); 247 | }); 248 | } 249 | 250 | cancelPoll() { 251 | logger.info('disable longpolling'); 252 | this.m_polling = null; 253 | } 254 | 255 | _poll() { 256 | if (this.m_polling !== null) { 257 | request({ 258 | uri: `https://${this.m_polling.server}`, 259 | method: 'GET', 260 | qs: { 261 | act: 'a_check', 262 | key: this.m_polling.key, 263 | ts: this.m_polling.ts, 264 | wait: 25, 265 | mode: 2 266 | }, 267 | timeout: 10 * 60 * 60, 268 | }, (err, response, body) => { 269 | if (err !== null || response == undefined || response.statusCode !== 200) { 270 | logger.warn('longpoll server', err, (response != undefined) ? response.statusCode : void(0)); 271 | return this._poll(); 272 | } 273 | const result = JSON.parse(body); 274 | this.m_polling.ts = result.ts; 275 | result.updates.forEach((event) => this.m_polling.callback(event[0], event.slice(1))); 276 | this._poll(); 277 | }); 278 | } 279 | } 280 | 281 | call(name, params, callback) { 282 | let methodBuilder = new MethodBuilder(); 283 | 284 | methodBuilder.setMethodName(name); 285 | methodBuilder.setToken(this.m_token); 286 | methodBuilder.setApiVersion(this.m_version); 287 | methodBuilder.setParams(params); 288 | methodBuilder.setCallback(callback); 289 | 290 | logger.info('push new request to stack', name, params); 291 | 292 | this.m_queue.push(methodBuilder.getMethodInfo()); 293 | } 294 | } 295 | 296 | module.exports = VKAPIWrapper; -------------------------------------------------------------------------------- /pawno/xml/pawndoc.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <xsl:value-of select="doc/assembly/name"/> 10 | 49 | 50 | 51 |

52 | 53 | 54 | 55 | 56 |
57 | 58 | 59 | 60 |
61 |
62 | 63 | 64 | 65 | 66 |

enumeration

67 | 68 | 69 |

Remarks

70 | 71 | 72 |

73 |
74 |
75 | 76 |

Members

77 |
78 | 79 |
80 |
81 | 82 | 83 |

Used by

84 |
85 |
86 | 87 |

Depends on

88 |
89 |
90 | 91 | 92 |

See Also

93 |
94 |
95 |
96 | 97 |

constant

98 | 99 |

Value

100 | 101 | 102 | 103 |

Remarks

104 | 105 | 106 |

107 |
108 |
109 | 110 | 111 |

Used by

112 |
113 |
114 | 115 |

Depends on

116 |
117 |
118 | 119 | 120 |

See Also

121 |
122 |
123 |
124 | 125 |

function

126 | 127 |

Syntax

128 | 129 |

130 |
131 | 132 | 133 | 134 |

Remarks

135 | 136 | 137 |

138 |
139 |
140 | 141 | 142 |

Used by

143 |
144 |
145 | 146 |

Depends on

147 |
148 |
149 | 150 |

Attributes

151 |
152 |
153 | 154 | 155 |

Transition table

156 |

157 | 158 | 159 | 160 |
SourceTargetCondition
161 |

162 |
163 | 164 | 165 | 166 |

See Also

167 |
168 |
169 |
170 | 171 |

variable

172 | 173 |

Syntax

174 | 175 | 176 |

Remarks

177 | 178 | 179 |

180 |
181 |
182 | 183 | 184 |

Used by

185 |
186 |
187 | 188 |

Depends on

189 |
190 |
191 | 192 | 193 |

See Also

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 |
Tag

220 |
221 | 222 | 223 |

224 | 225 | 226 |
Size

227 |
228 | 229 | 230 |

Returns

231 |

232 |
233 | 234 | 235 |

Defined in

236 |

, line

237 |
238 | 239 | 240 |

241 |
242 | 243 | 244 |

Example

245 |

246 |
247 | 248 | 249 |
  • 250 |
    251 | 252 | 253 |
  • #()
  • 254 |
    255 | 256 | 257 |
  • #()
  • 258 |
    259 | 260 | 261 |

    Estimated stack usage

    262 |

    cells

    263 |
    264 | 265 | 266 |

    Automaton

    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 | -------------------------------------------------------------------------------- /bot.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const VKBot = require('./vk_bot'); 4 | const child_process = require('child_process'); 5 | const request = require('request'); 6 | const cleanup = require('./wiki_cleanup'); 7 | const UserList = require('./lists'); 8 | const randomlib = require('./random'); 9 | const dns = require('dns'); 10 | const cheerio = require('cheerio'); 11 | const fs = require('fs'); 12 | const downloadFile = require('./file_downloader'); 13 | const fork = require('child_process').fork; 14 | const dice = require('./scripts/__dice'); 15 | const Pawn = require('./pawn'); 16 | const get_code_from_gist = require('./gist'); 17 | 18 | const account = { 19 | login: 'fuckgg', 20 | password: 'fuuuuuu', 21 | key: 'what the hell' 22 | }; 23 | 24 | const bot = new VKBot(account); 25 | 26 | setDescription(bot); 27 | 28 | bot.on('who', function(info, args, query) { 29 | const MEMES = ['Это ...', 'это ...', 'ЭТО ...']; 30 | 31 | if (info.peer >= 2e9) 32 | this.getListOfChatUsers(info.peer, (error, users) => { 33 | if (error) 34 | return this.response(this.peer, 'Ошибка какая-то ...', null, [ info.message ]); 35 | 36 | const user = randomlib.random_element(users); 37 | 38 | this.response(info.peer, `${randomlib.random_element(MEMES)} ${user.first_name} ${user.last_name}`, null, [ info.message ]); 39 | }); 40 | else 41 | this.response(info.peer, 'Команда закрыта на технические работы ...'); 42 | }); 43 | 44 | bot.on('ping', function(info, args, query) { 45 | const type = (args[0] !== undefined) ? args[0] : 'site'; 46 | 47 | if (type === 'site') { 48 | child_process.exec(`ping "${query}" | find "Average"`, (error, stdout, stderr) => { 49 | if (error || stderr.length !== 0) 50 | return this.response(info.peer, 'Неверный адрес.'); 51 | this.response(info.peer, `Ping ${query}:\n${stdout.trim()}`); 52 | }); 53 | } 54 | else 55 | this.response(info.peer, 'Ты глупый что ли?'); 56 | }); 57 | 58 | bot.on('wiki', function(info, args, query) { 59 | const lang = (args[0] !== undefined) ? args[0] : 'ru'; 60 | const count = (args[1] !== undefined) ? args[1] : 1; 61 | 62 | request({ 63 | uri: `https://${lang}.wikipedia.org/w/api.php`, 64 | qs: { 65 | action: 'query', 66 | srlinit: count, 67 | list: 'search', 68 | srsearch: query, 69 | format: 'json' 70 | } 71 | }, (err, response, body) => { 72 | if (err !== null) 73 | return; 74 | 75 | const result = JSON.parse(body); 76 | let message = new String(); 77 | 78 | for (let i = 0; i < count; i++) { 79 | if (result.query !== undefined && result.query.search !== undefined && result.query.search[i] !== undefined) 80 | message += `https://${lang}.wikipedia.org/wiki/${result.query.search[i].title.replace(/\s/g, '_')}\n`; 81 | } 82 | 83 | this.response(info.peer, message); 84 | }); 85 | }); 86 | 87 | bot.on('def', function(info, args, query) { 88 | if (query === undefined) 89 | return this.response(info.peer, 'Команда @def должна принимать значение. Подробнее @help.'); 90 | 91 | request({ 92 | uri: 'https://ru.wiktionary.org/w/api.php', 93 | qs: { 94 | action: 'query', 95 | titles: query, 96 | rvprop: 'content', 97 | prop: 'revisions', 98 | format: 'json' 99 | } 100 | }, (err, response, body) => { 101 | if (err !== null) 102 | return this.response(info.peer, 'Дети-404. Not found!', null, info.message); 103 | 104 | const result = JSON.parse(body); 105 | 106 | if (result == void(0) || result.query == void(0) || result.query.pages == void(0)) 107 | return; 108 | 109 | const keys = Object.keys(result.query.pages); 110 | 111 | if (keys.length === 0) 112 | return; 113 | 114 | if (result.query.pages[keys[0]].revisions === undefined || result.query.pages[keys[0]].revisions.length === 0) 115 | return; 116 | 117 | const defs = cleanup(result.query.pages[keys[0]].revisions[0]["*"]); 118 | if (defs === null) 119 | return; 120 | 121 | this.response(info.peer, defs.map((def, index) => (def.length > 1) ? `${index + 1}. ${def}` : void(0)).join('\n'), null, [ info.message ]); 122 | }); 123 | }); 124 | 125 | bot.on('listof', function(info, args, query) { 126 | let count = (args[0] !== undefined) ? args[0] : 5; 127 | 128 | if (info.peer < 2e9) 129 | return this.response(info.peer, 'Команда на реконструкции ...'); 130 | 131 | this.getListOfChatUsers(info.peer, (err, users) => { 132 | if (err) 133 | return; 134 | 135 | if (count > users.length) 136 | count = users.length; 137 | 138 | const list = new UserList(users); 139 | let message = `Лист ${query}:`; 140 | 141 | for (let i = 1; i <= count; i++) 142 | message += `\n${i}. ${list.getOnlyName()}`; 143 | 144 | this.response(info.peer, message); 145 | }); 146 | }); 147 | 148 | bot.on('resolve', function(info, args, query) { 149 | if (query === undefined) 150 | return this.response(info.peer, 'Необходимы параметры для команды @resolve. Введите @help.'); 151 | 152 | dns.lookup(query, (error, address, family) => { 153 | if (error) 154 | return this.response(info.peer, 'Ошибка получения адреса.'); 155 | this.response(info.peer, `${query} имеет адрес ${address}`, null, [ info.message ]); 156 | }); 157 | }); 158 | 159 | bot.on('eoff', function(info, args, query) { 160 | request({ 161 | uri: 'http://www.russki-mat.net/e/mat_slovar.htm', 162 | method: 'GET' 163 | }, (error, response, body) => { 164 | if (error || response.statusCode !== 200) 165 | return; 166 | 167 | const MEMES = cheerio.load(body)('.art > .lem'); 168 | const who = randomlib.random_element(['денисов', 'аакерманова-шлюха']); 169 | 170 | this.response(info.peer, `${who} ты ${randomlib.random_element(MEMES).children[0].data}!!`); 171 | }); 172 | }); 173 | 174 | bot.on('meme', function(info, args, query) { 175 | const type = (args[0] !== undefined) ? args[0] : '1001mem'; 176 | 177 | const callback = (error, result) => { 178 | if (error) 179 | return this.response(info.peer, 'Не удалось получить мем, прости ...'); 180 | 181 | if (result.type == 'attachment') 182 | return this.response(info.peer, '', [ result.content ], [ info.message ]); 183 | 184 | if (result.type == 'text') 185 | return this.response(info.peer, result.content, null, [ info.message ]); 186 | 187 | if (result.type == 'image') { 188 | const uri = result.content; 189 | const filename = `./upload/${randomlib.random(0, 1000)}_${uri.slice(uri.lastIndexOf('\/') + 1, uri.length)}`; 190 | 191 | downloadFile(uri, filename, (error, result) => { 192 | if (error) 193 | return this.response(info.peer, 'Ошибка ...'); 194 | this.uploadImage(filename, (error, result) => { 195 | fs.unlink(filename, () => void(0)); 196 | 197 | if (error || result.length === 0) 198 | return; 199 | 200 | const picture = result[0]; 201 | return this.response(info.peer, '', [ `photo${picture.owner_id}_${picture.id}` ], [ info.message ]); 202 | }); 203 | }); 204 | } 205 | }; 206 | 207 | switch(type) { 208 | case '1001mem': 209 | getMemeFrom1001Mem(callback); 210 | break; 211 | case 'yandex': 212 | getMemeFromYandexRu(args[1] || 1, callback); 213 | break; 214 | case 'vk': 215 | const publicName = (args[1] !== undefined) ? args[1] : null; 216 | const fromId = (!isNaN(parseInt(args[2]))) ? parseInt(args[2]) : 0; 217 | 218 | if (publicName == null) 219 | return this.response(info.peer, 'Неизвестный мемоконтент источник!'); 220 | 221 | this.vk.call('wall.get', { domain: publicName, count: 1 }, (error, result) => { 222 | if (error || result.count === 0) 223 | return this.response(info.peer, 'Здесь нет мемов!', null, [ info.message ]); 224 | 225 | const index = randomlib.random(fromId, result.count - 1); 226 | 227 | this.vk.call('wall.get', { domain: publicName, count: 1, offset: index }, (error, result) => { 228 | if (error || result.items === undefined || result.items.length === 0) 229 | return this.response(info.peer, 'Здесь нет мемов!', null, [ info.message ]); 230 | 231 | const post = result.items[0]; 232 | return this.response(info.peer, '', [ `wall${post.owner_id}_${post.id}` ]); 233 | }); 234 | }); 235 | 236 | break; 237 | default: 238 | args.unshift('vk'); 239 | this.emit('meme', info, args, query); 240 | //this.response(info.peer, 'Неизвестный мемоконтент источник!'); 241 | } 242 | }); 243 | 244 | bot.on('eval', function(info, args, query) { 245 | const virtualMachine = fork('./async_eval.js', [ query ]); 246 | virtualMachine.on('message', message => { 247 | if (message.success) 248 | this.response(info.peer, `Result: ${message.result}`); 249 | else 250 | this.response(info.peer, 'Не осилил выполнить твой код ...'); 251 | }); 252 | }); 253 | 254 | bot.on('calc', function(info, args, query) { 255 | this.emit('eval', info, args, `return ${query};`); 256 | }); 257 | 258 | bot.on('script', function(info, args, query) { 259 | const command = (args[0] !== undefined) ? args[0] : 'run'; 260 | 261 | if (query === undefined) 262 | return this.response(info.peer, 'Вы не указали имя скрипта для запуска.'); 263 | 264 | const filename = `./scripts/${query}.js`; 265 | 266 | switch (command) { 267 | case 'run': 268 | if (!fs.existsSync(filename, fs.R_OK)) 269 | return this.response(info.peer, `Скрипта с именем "${query}" не существует.`); 270 | 271 | fs.readFile(filename, (error, text) => { 272 | if (error) 273 | return this.response(info.peer, `Произошла ошибка при загрузке скрипта.`); 274 | 275 | const virtualMachine = fork('./async_eval.js', [ text, JSON.stringify(args.slice(1)) ]); 276 | 277 | virtualMachine.on('message', message => { 278 | if (message.success) 279 | this.response(info.peer, message.result); 280 | else 281 | this.response(info.peer, 'Произошла ошибка при исполнении кода.'); 282 | }); 283 | }); 284 | 285 | break; 286 | case 'create': 287 | break; 288 | case 'list': 289 | break; 290 | default: 291 | } 292 | }); 293 | 294 | bot.on('dice', function(info, args, query) { 295 | if (query === undefined && args.length === 0) 296 | return this.response(info.peer, 'Для игры в @dice нужно ввести ставку и оппонента.'); 297 | 298 | const command = (args[0] !== undefined) ? args[0] : 'bet'; 299 | 300 | switch (command) { 301 | case 'bet': { 302 | const opponent = (args[1] !== undefined) ? parseInt(args[1]) : 0; 303 | const bet = parseInt(query); 304 | 305 | const play = (opponent) => { 306 | if (opponent <= 0 || opponent >= 2e9) 307 | return this.response(info.peer, 'Вы ввели недействительный ID пользователя.', null, [ info.message ]); 308 | 309 | const result = dice.bet(info.sender, opponent, bet); 310 | 311 | if (result.success) 312 | this.response(info.peer, 'Вы успешно выдвинули предложение сыграть с вами.', null, [ info.message ]); 313 | else 314 | this.response(info.peer, `Ошибка! ${result.reason}`, null, [ info.message ]); 315 | }; 316 | 317 | 318 | 319 | if (isNaN(opponent)) { 320 | this.resolveScreenName(args[1], (error, result) => { 321 | if (!error && result.type === 'user') 322 | return play(result.object_id); 323 | else 324 | return this.response(info.peer, 'Вы ввели screenname не пользователя.', null, [ info.message ]); 325 | }); 326 | } 327 | else 328 | play(opponent); 329 | 330 | break; 331 | } 332 | case 'top': { 333 | const top = dice.getTop(); 334 | 335 | this.vk.call('users.get', { user_ids: top.join(',') }, (error, users) => { 336 | if (error) 337 | return this.response(info.peer, 'Не удалось получить топ, простите ...', null, [ info.message ]); 338 | 339 | const message = users.map((user, index) => `${index + 1}. ${user.first_name} ${user.last_name} имеет ${dice.getBalance(user.id)}$`).join('\n'); 340 | 341 | this.response(info.peer, `Топ @dice:\n${message}`, null, [ info.message ]); 342 | }); 343 | 344 | break; 345 | } 346 | case 'balance': { 347 | const balance = dice.getBalance(info.sender); 348 | if (balance === null) 349 | this.response(info.peer, 'Вы не зарегистрированны!', null, [ info.message ]); 350 | else 351 | this.response(info.peer, `Ваш балас на данный момент ${balance}$.`, null, [ info.message ]); 352 | break; 353 | } 354 | case 'accept': { 355 | const result = dice.play(info.sender); 356 | if (result.success) { 357 | if (result.winner) 358 | this.response(info.peer, `Поздравляем, вы победили!\nВаш баланс: ${result.balance}$.`, null, [ info.message ]); 359 | else 360 | this.response(info.peer, `Поздравляем, вы проиграли!\nВаш баланс: ${result.balance}$.`, null, [ info.message ]); 361 | } else 362 | this.response(info.peer, `Упс, ошибка: ${result.reason}`, null, [ info.message ]); 363 | break; 364 | } 365 | case 'decline': { 366 | const result = dice.decline(info.sender); 367 | if (result.success) 368 | this.response(info.peer, 'Вы успешно отменили встречное предложение.', null, [ info.message ]); 369 | else 370 | this.response(info.peer, `Ошибка: ${result.reason}`, null, [ info.message ]); 371 | break; 372 | } 373 | case 'reg': 374 | case 'reset': 375 | dice.reset(info.sender); 376 | this.response(info.peer, 'Теперь на вашем балансе 100$!', null, [ info.message ]); 377 | break; 378 | default: 379 | this.response(info.peer, 'Неизвестная команда для игры в @dice.'); 380 | } 381 | }); 382 | 383 | bot.on('pawn', function(info, args, query) { 384 | get_code_from_gist(query, (error, code) => { 385 | if (error) 386 | return this.response(info.peer, 'Не удалось получить код по ссылке.', null, [ info.message ]); 387 | 388 | const pawn = new Pawn(code); 389 | pawn.compile((error, warnings) => { 390 | if (error) 391 | return this.response(info.peer, `${error.length} errors:\n${error.join('\n')}`, null, [ info.message ]); 392 | 393 | if (warnings.length > 0) 394 | this.response(info.peer, `${warnings.length} warnings:\n${warnings.join('\n')}`, null, [ info.message ]); 395 | 396 | pawn.on('say', args => this.response(info.peer, `Message from pawn: ${pawn.getString(args[0])}`)); 397 | 398 | pawn.run((error, result) => { 399 | if (error) 400 | return this.response(info.peer, 'Ошибка при выполнении кода.'); 401 | 402 | return this.response(info.peer, `Результат выполнения: ${result}`); 403 | }); 404 | }); 405 | }); 406 | }); 407 | 408 | function getMemeFromYandexRu(count, callback) { 409 | if (callback == undefined) 410 | return; 411 | 412 | if (count > 20) 413 | count = 20; 414 | 415 | request.get('http://export.yandex.ru/last/last20x.xml', (error, response, body) => { 416 | if (error || response.statusCode !== 200) 417 | return callback(error); 418 | 419 | let message = new String(); 420 | 421 | for (let i = 0; i < count; i++) { 422 | message += `\n${cheerio.load(body)('page > last20x > item').get(i).children[0].data}`; 423 | } 424 | 425 | callback(null, { type: 'text', content: message }); 426 | }); 427 | } 428 | 429 | function getMemeFrom1001Mem(callback) { 430 | if (callback == undefined) 431 | return; 432 | 433 | const page = randomlib.random(1, 1000); 434 | 435 | request.get(`http://1001mem.ru/best/${page}`, (error, response, body) => { 436 | if (error || response.statusCode !== 200) 437 | return callback(error); 438 | 439 | const articles = cheerio.load(body)('.posts > article'); 440 | 441 | if (articles.length === 0) 442 | return callback(error); 443 | 444 | const article = randomlib.random_element(articles); 445 | const uri = article.children[3].children[1].children[1].children[1].attribs.src; 446 | 447 | callback(null, { type: 'image', content: uri }); 448 | }); 449 | } 450 | 451 | function setDescription(bot) { 452 | bot.setDescriptionForCmd('wiki', { 453 | description: 'Позволяет получить ссылки на статьи с сайта wikipedia.org.', 454 | syntax: 'wiki([lang], [count]) %query%', 455 | args: [{ 456 | name: 'lang', 457 | description: 'Язык поиска статьи.' 458 | }, { 459 | name: 'count', 460 | description: 'Количество возвращаемых результатов.' 461 | }, { 462 | name: 'query', 463 | description: 'Запрос, по которому производить поиск статей.' 464 | } 465 | ], 466 | examples: ['@wiki Сталин', '@wiki(en) API', '@wiki(ru, 5) 1995'] 467 | }); 468 | 469 | bot.setDescriptionForCmd('ping', { 470 | description: 'Выполнить команду ping с введенным адресом.', 471 | syntax: 'ping %address%', 472 | args: [{ 473 | name: 'address', 474 | description: 'Адрес сайта.' 475 | } 476 | ], 477 | examples: ['@ping google.com', '@ping api.vk.com'] 478 | }); 479 | 480 | bot.setDescriptionForCmd('who', { 481 | description: 'Мемная команда, которая говорит кто ...', 482 | syntax: 'who' 483 | }); 484 | 485 | bot.setDescriptionForCmd('def', { 486 | description: 'Получить описание слова с сайта wiktionary.org', 487 | syntax: 'def %query%', 488 | args: [{ 489 | name: 'query', 490 | description: 'Слово, которое нужно найти.' 491 | } 492 | ], 493 | examples: ['@def насвай', '@def поиск'] 494 | }); 495 | 496 | bot.setDescriptionForCmd('listof', { 497 | description: 'Выводит список случайных пользователей конференции.', 498 | syntax: 'listof([count]) %name%', 499 | args: [{ 500 | name: 'count', 501 | description: 'Количество пользователей в списке.' 502 | }, { 503 | name: 'name', 504 | description: 'Название списка.' 505 | } 506 | ], 507 | examples: ['@listof МойСписок', '@listof(10) Десять случайных пользователей'] 508 | }); 509 | 510 | bot.setDescriptionForCmd('dice', { 511 | description: 'Игра в кости.', 512 | syntax: 'dice(%action% [, ..args]) [query]', 513 | args: [{ 514 | name: 'action', 515 | description: 'Действие в игре. Доступные: reg, bet, reset, decline, accept, top, balance.' 516 | }, { 517 | name: 'args, query', 518 | description: 'Дополнительные аргументы.' 519 | } 520 | ], 521 | examples: [ 522 | '@dice(reg) — регистрация в игре.', 523 | '@dice(bet, 86711420) 100 — предложение игры на 100$ (вместо ID можно screenname).', 524 | '@dice(reset) — объявить себя банкротом и сбросить баланс.', 525 | '@dice(decline) — отменить последнее предложение.', 526 | '@dice(accept) — принять последнее предложение.', 527 | '@dice(top) — показать топ-5 богачей.', 528 | '@dice(balance) — вывести свой баланс.' 529 | ] 530 | }); 531 | 532 | bot.setDescriptionForCmd('resolve', { 533 | description: 'Получает IP адрес к которому прикреплен домен.', 534 | syntax: 'resolve %domain%', 535 | args: [{ 536 | name: 'domain', 537 | description: 'Домен ...' 538 | } 539 | ], 540 | examples: [ '@resolve server.rp-skyland.ru' ] 541 | }); 542 | 543 | bot.setDescriptionForCmd('meme', { 544 | description: 'Получает смешной meme с разных источников', 545 | syntax: 'meme([source, ..args])', 546 | args: [{ 547 | name: 'source', 548 | description: 'Мемоисточник. Доступны: 1001mem (по умолчанию), yandex, vk' 549 | } 550 | ], 551 | examples: [ 552 | '@meme — получает мем с 1001mem.', 553 | '@meme(yandex) — получает мем с яндекса.', 554 | '@meme(yandex, 10) — получает 10 (десять) мемов с яндекса.', 555 | '@meme(mdk) — получает мем с MDK ...', 556 | '@meme(vk, publicname) — получает мем с любого паблика ВКонтакте.', 557 | '@meme(publicname) — пока что можно и так ...' 558 | ] 559 | }); 560 | 561 | bot.setDescriptionForCmd('eval', { 562 | description: 'Выполняет JavaScript код online.', 563 | syntax: 'eval %code%', 564 | args: [{ 565 | name: 'code', 566 | description: 'Код, что нужно выполнить.' 567 | } 568 | ], 569 | examples: ['@eval return [5, 1, 2, 4, 3].sort((a, b) => a - b)'] 570 | }); 571 | 572 | bot.setDescriptionForCmd('calc', { 573 | description: 'Выполняет математические операции.', 574 | syntax: 'calc %expression%', 575 | args: [{ 576 | name: 'expression', 577 | description: 'Выражение для вычисления.' 578 | } 579 | ], 580 | examples: ['@calc 2 * 2 + Math.log2(2 << 3)'] 581 | }); 582 | 583 | bot.setDescriptionForCmd('script', { 584 | description: 'Операции с кастомными скриптами.', 585 | syntax: 'script(%command% [, ..args]) [query]', 586 | args: [{ 587 | name: '', 588 | description: '' 589 | } 590 | ], 591 | examples: [] 592 | }); 593 | 594 | bot.setDescriptionForCmd('pawn', { 595 | description: 'Запускает скрипт pawn с gist.github.com.', 596 | syntax: '@pawn %link%', 597 | args: [{ 598 | name: 'link', 599 | description: 'Ссылка на gist.github.com' 600 | } 601 | ], 602 | examples: ['@pawn https://gist.github.com/zottce/6c5ec06ed494951790b6 — Запуск скрипта.'] 603 | }); 604 | 605 | /*bot.setDescriptionForCmd('', { 606 | description: '', 607 | syntax: '', 608 | args: [{ 609 | name: '', 610 | description: '' 611 | } 612 | ], 613 | examples: [] 614 | });*/ 615 | } -------------------------------------------------------------------------------- /node-amx/amx.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Kester Everts 2012 3 | */ 4 | 5 | var AMXHeader = require("./amxheader").AMXHeader; 6 | var fs = require("fs"); 7 | var assert = require("assert"); 8 | 9 | function AMX() { 10 | /* 11 | * @type AMXHeader 12 | */ 13 | this.base = null; 14 | this.code = null; 15 | this.codesize = 0; 16 | this.hlw = 0; 17 | this.stp = 0; 18 | this.hea = 0; 19 | this.stk = 0; 20 | this.cip = 0; 21 | this.frm = 0; 22 | this.alt = 0; 23 | this.reset_stk = 0; 24 | this.reset_hea = 0; 25 | this.paramcount = 0; 26 | this.callback = AMX.prototype.callback; 27 | this.debug = 0; 28 | this.flags = 0; 29 | this.error = 0; 30 | this.pri = 0; 31 | this.sysreq_d = 0; 32 | this.publics = []; 33 | this.natives = []; 34 | this.buffer = null; 35 | this.callbacks = {}; 36 | } 37 | 38 | const AMX_COMPACTMARGIN = 64; 39 | const AMX_CELL_SIZE = 4; 40 | const AMX_FLAG_COMPACT = 0x04; 41 | const AMX_EXEC_MAIN = -1; 42 | const AMX_EXEC_CONT = -2; 43 | const sEXPMAX = 19; 44 | 45 | const OP_NONE = 0; 46 | const OP_LOAD_PRI = 1; 47 | const OP_LOAD_ALT = 2; 48 | const OP_LOAD_S_PRI = 3; 49 | const OP_LOAD_S_ALT = 4; 50 | const OP_LREF_PRI = 5; 51 | const OP_LREF_ALT = 6; 52 | const OP_LREF_S_PRI = 7; 53 | const OP_LREF_S_ALT = 8; 54 | const OP_LOAD_I = 9; 55 | const OP_LODB_I = 10; 56 | const OP_CONST_PRI = 11; 57 | const OP_CONST_ALT = 12; 58 | const OP_ADDR_PRI = 13; 59 | const OP_ADDR_ALT = 14; 60 | const OP_STOR_PRI = 15; 61 | const OP_STOR_ALT = 16; 62 | const OP_STOR_S_PRI = 17; 63 | const OP_STOR_S_ALT = 18; 64 | const OP_SREF_PRI = 19; 65 | const OP_SREF_ALT = 20; 66 | const OP_SREF_S_PRI = 21; 67 | const OP_SREF_S_ALT = 22; 68 | const OP_STOR_I = 23; 69 | const OP_STRB_I = 24; 70 | const OP_LIDX = 25; 71 | const OP_LIDX_B = 26; 72 | const OP_IDXADDR = 27; 73 | const OP_IDXADDR_B = 28; 74 | const OP_ALIGN_PRI = 29; 75 | const OP_ALIGN_ALT = 30; 76 | const OP_LCTRL = 31; 77 | const OP_SCTRL = 32; 78 | const OP_MOVE_PRI = 33; 79 | const OP_MOVE_ALT = 34; 80 | const OP_XCHG = 35; 81 | const OP_PUSH_PRI = 36; 82 | const OP_PUSH_ALT = 37; 83 | const OP_PUSH_R = 38; 84 | const OP_PUSH_C = 39; 85 | const OP_PUSH = 40; 86 | const OP_PUSH_S = 41; 87 | const OP_POP_PRI = 42; 88 | const OP_POP_ALT = 43; 89 | const OP_STACK = 44; 90 | const OP_HEAP = 45; 91 | const OP_PROC = 46; 92 | const OP_RET = 47; 93 | const OP_RETN = 48; 94 | const OP_CALL = 49; 95 | const OP_CALL_PRI = 50; 96 | const OP_JUMP = 51; 97 | const OP_JREL = 52; 98 | const OP_JZER = 53; 99 | const OP_JNZ = 54; 100 | const OP_JEQ = 55; 101 | const OP_JNEQ = 56; 102 | const OP_JLESS = 57; 103 | const OP_JLEQ = 58; 104 | const OP_JGRTR = 59; 105 | const OP_JGEQ = 60; 106 | const OP_JSLESS = 61; 107 | const OP_JSLEQ = 62; 108 | const OP_JSGRTR = 63; 109 | const OP_JSGEQ = 64; 110 | const OP_SHL = 65; 111 | const OP_SHR = 66; 112 | const OP_SSHR = 67; 113 | const OP_SHL_C_PRI = 68; 114 | const OP_SHL_C_ALT = 69; 115 | const OP_SHR_C_PRI = 70; 116 | const OP_SHR_C_ALT = 71; 117 | const OP_SMUL = 72; 118 | const OP_SDIV = 73; 119 | const OP_SDIV_ALT = 74; 120 | const OP_UMUL = 75; 121 | const OP_UDIV = 76; 122 | const OP_UDIV_ALT = 77; 123 | const OP_ADD = 78; 124 | const OP_SUB = 79; 125 | const OP_SUB_ALT = 80; 126 | const OP_AND = 81; 127 | const OP_OR = 82; 128 | const OP_XOR = 83; 129 | const OP_NOT = 84; 130 | const OP_NEG = 85; 131 | const OP_INVERT = 86; 132 | const OP_ADD_C = 87; 133 | const OP_SMUL_C = 88; 134 | const OP_ZERO_PRI = 89; 135 | const OP_ZERO_ALT = 90; 136 | const OP_ZERO = 91; 137 | const OP_ZERO_S = 92; 138 | const OP_SIGN_PRI = 93; 139 | const OP_SIGN_ALT = 94; 140 | const OP_EQ = 95; 141 | const OP_NEQ = 96; 142 | const OP_LESS = 97; 143 | const OP_LEQ = 98; 144 | const OP_GRTR = 99; 145 | const OP_GEQ = 100; 146 | const OP_SLESS = 101; 147 | const OP_SLEQ = 102; 148 | const OP_SGRTR = 103; 149 | const OP_SGEQ = 104; 150 | const OP_EQ_C_PRI = 105; 151 | const OP_EQ_C_ALT = 106; 152 | const OP_INC_PRI = 107; 153 | const OP_INC_ALT = 108; 154 | const OP_INC = 109; 155 | const OP_INC_S = 110; 156 | const OP_INC_I = 111; 157 | const OP_DEC_PRI = 112; 158 | const OP_DEC_ALT = 113; 159 | const OP_DEC = 114; 160 | const OP_DEC_S = 115; 161 | const OP_DEC_I = 116; 162 | const OP_MOVS = 117; 163 | const OP_CMPS = 118; 164 | const OP_FILL = 119; 165 | const OP_HALT = 120; 166 | const OP_BOUNDS = 121; 167 | const OP_SYSREQ_PRI = 122; 168 | const OP_SYSREQ_C = 123; 169 | const OP_FILE = 124; 170 | const OP_LINE = 125; 171 | const OP_SYMBOL = 126; 172 | const OP_SRANGE = 127; 173 | const OP_JUMP_PRI = 128; 174 | const OP_SWITCH = 129; 175 | const OP_CASETBL = 130; 176 | const OP_SWAP_PRI = 131; 177 | const OP_SWAP_ALT = 132; 178 | const OP_PUSHADDR = 133; 179 | const OP_NOP = 134; 180 | const OP_SYSREQ_D = 135; 181 | const OP_SYMTAG = 136; 182 | const OP_BREAK = 137; 183 | const OP_NUM_OPCODES = 138; 184 | 185 | AMX.OPCODES = [ 'OP_NONE', 186 | 'OP_LOAD_PRI', 187 | 'OP_LOAD_ALT', 188 | 'OP_LOAD_S_PRI', 189 | 'OP_LOAD_S_ALT', 190 | 'OP_LREF_PRI', 191 | 'OP_LREF_ALT', 192 | 'OP_LREF_S_PRI', 193 | 'OP_LREF_S_ALT', 194 | 'OP_LOAD_I', 195 | 'OP_LODB_I', 196 | 'OP_CONST_PRI', 197 | 'OP_CONST_ALT', 198 | 'OP_ADDR_PRI', 199 | 'OP_ADDR_ALT', 200 | 'OP_STOR_PRI', 201 | 'OP_STOR_ALT', 202 | 'OP_STOR_S_PRI', 203 | 'OP_STOR_S_ALT', 204 | 'OP_SREF_PRI', 205 | 'OP_SREF_ALT', 206 | 'OP_SREF_S_PRI', 207 | 'OP_SREF_S_ALT', 208 | 'OP_STOR_I', 209 | 'OP_STRB_I', 210 | 'OP_LIDX', 211 | 'OP_LIDX_B', 212 | 'OP_IDXADDR', 213 | 'OP_IDXADDR_B', 214 | 'OP_ALIGN_PRI', 215 | 'OP_ALIGN_ALT', 216 | 'OP_LCTRL', 217 | 'OP_SCTRL', 218 | 'OP_MOVE_PRI', 219 | 'OP_MOVE_ALT', 220 | 'OP_XCHG', 221 | 'OP_PUSH_PRI', 222 | 'OP_PUSH_ALT', 223 | 'OP_PUSH_R', 224 | 'OP_PUSH_C', 225 | 'OP_PUSH', 226 | 'OP_PUSH_S', 227 | 'OP_POP_PRI', 228 | 'OP_POP_ALT', 229 | 'OP_STACK', 230 | 'OP_HEAP', 231 | 'OP_PROC', 232 | 'OP_RET', 233 | 'OP_RETN', 234 | 'OP_CALL', 235 | 'OP_CALL_PRI', 236 | 'OP_JUMP', 237 | 'OP_JREL', 238 | 'OP_JZER', 239 | 'OP_JNZ', 240 | 'OP_JEQ', 241 | 'OP_JNEQ', 242 | 'OP_JLESS', 243 | 'OP_JLEQ', 244 | 'OP_JGRTR', 245 | 'OP_JGEQ', 246 | 'OP_JSLESS', 247 | 'OP_JSLEQ', 248 | 'OP_JSGRTR', 249 | 'OP_JSGEQ', 250 | 'OP_SHL', 251 | 'OP_SHR', 252 | 'OP_SSHR', 253 | 'OP_SHL_C_PRI', 254 | 'OP_SHL_C_ALT', 255 | 'OP_SHR_C_PRI', 256 | 'OP_SHR_C_ALT', 257 | 'OP_SMUL', 258 | 'OP_SDIV', 259 | 'OP_SDIV_ALT', 260 | 'OP_UMUL', 261 | 'OP_UDIV', 262 | 'OP_UDIV_ALT', 263 | 'OP_ADD', 264 | 'OP_SUB', 265 | 'OP_SUB_ALT', 266 | 'OP_AND', 267 | 'OP_OR', 268 | 'OP_XOR', 269 | 'OP_NOT', 270 | 'OP_NEG', 271 | 'OP_INVERT', 272 | 'OP_ADD_C', 273 | 'OP_SMUL_C', 274 | 'OP_ZERO_PRI', 275 | 'OP_ZERO_ALT', 276 | 'OP_ZERO', 277 | 'OP_ZERO_S', 278 | 'OP_SIGN_PRI', 279 | 'OP_SIGN_ALT', 280 | 'OP_EQ', 281 | 'OP_NEQ', 282 | 'OP_LESS', 283 | 'OP_LEQ', 284 | 'OP_GRTR', 285 | 'OP_GEQ', 286 | 'OP_SLESS', 287 | 'OP_SLEQ', 288 | 'OP_SGRTR', 289 | 'OP_SGEQ', 290 | 'OP_EQ_C_PRI', 291 | 'OP_EQ_C_ALT', 292 | 'OP_INC_PRI', 293 | 'OP_INC_ALT', 294 | 'OP_INC', 295 | 'OP_INC_S', 296 | 'OP_INC_I', 297 | 'OP_DEC_PRI', 298 | 'OP_DEC_ALT', 299 | 'OP_DEC', 300 | 'OP_DEC_S', 301 | 'OP_DEC_I', 302 | 'OP_MOVS', 303 | 'OP_CMPS', 304 | 'OP_FILL', 305 | 'OP_HALT', 306 | 'OP_BOUNDS', 307 | 'OP_SYSREQ_PRI', 308 | 'OP_SYSREQ_C', 309 | 'OP_FILE', 310 | 'OP_LINE', 311 | 'OP_SYMBOL', 312 | 'OP_SRANGE', 313 | 'OP_JUMP_PRI', 314 | 'OP_SWITCH', 315 | 'OP_CASETBL', 316 | 'OP_SWAP_PRI', 317 | 'OP_SWAP_ALT', 318 | 'OP_PUSHADDR', 319 | 'OP_NOP', 320 | 'OP_SYSREQ_D', 321 | 'OP_SYMTAG', 322 | 'OP_BREAK', 323 | 'OP_NUM_OPCODES' ]; 324 | 325 | AMX.MAGIC = 0xf1e0; // we always assume a 32-bit cell size 326 | AMX.CUR_FILE_VERSION = 10; 327 | AMX.MIN_FILE_VERSION = 6; 328 | AMX.MIN_AMX_VERSION = 8; 329 | AMX.COMPACTMARGIN = AMX_COMPACTMARGIN; 330 | 331 | AMX.init = function(buffer) { 332 | var amx = new AMX(); 333 | amx.buffer = buffer; 334 | var hdr = new AMXHeader(buffer); 335 | if(hdr.magic != AMX.MAGIC) { 336 | throw new AMX.Error("AMX_ERR_FORMAT", "Magic constant does not match."); 337 | } 338 | if(hdr.file_version < AMX.MIN_FILE_VERSION || hdr.amx_version > AMX.CUR_FILE_VERSION) { 339 | throw new AMX.Error("AMX_ERR_VERSION", "Version not supported."); 340 | } 341 | if (hdr.stp <=0) { 342 | throw new AMX.Error("AMX_ERR_FORMAT", "hdr.stp <= 0"); 343 | } 344 | 345 | 346 | assert((hdr.flags & AMX_FLAG_COMPACT) !=0 || hdr.hea == hdr.size); 347 | if ((hdr.flags & AMX_FLAG_COMPACT) !=0 ) { 348 | expand(buffer.slice(hdr.cod), hdr.size - hdr.cod, hdr.hea - hdr.cod); 349 | } 350 | 351 | amx.base = hdr; 352 | 353 | amx.hlw = hdr.hea - hdr.dat; 354 | amx.stp = hdr.stp - hdr.dat - AMX_CELL_SIZE; 355 | amx.hea = amx.hlw; 356 | amx.stk = amx.stp; 357 | 358 | amx.code = buffer.slice(hdr.cod); 359 | amx.codesize = hdr.dat - hdr.cod; 360 | 361 | var data = buffer.slice(hdr.dat); 362 | 363 | data.writeInt32LE(0, hdr.stp - hdr.dat - AMX_CELL_SIZE); 364 | 365 | var numPublics = (hdr.natives - hdr.publics) / hdr.defsize; 366 | 367 | for(var i = 0; i < numPublics; i++) { 368 | amx.publics[i] = new FuncStub(amx, hdr.publics, i); 369 | } 370 | 371 | var numNatives = (hdr.libraries - hdr.natives) / hdr.defsize; 372 | 373 | for(var i = 0; i < numNatives; i++) { 374 | amx.natives[i] = new FuncStub(amx, hdr.natives, i); 375 | } 376 | 377 | return amx; 378 | } 379 | 380 | AMX.prototype.exec = function(index) { 381 | var hdr; 382 | var code, data; 383 | var pri, alt, stk, frm, hea; 384 | var reset_stk, reset_hea, cip; 385 | var codesize; 386 | var i; 387 | var op; 388 | var offs; 389 | var num; 390 | 391 | if(typeof this.callback != "function") { 392 | throw AMX.Error("AMX_ERR_CALLBACK", ""); 393 | } 394 | 395 | hdr = this.base; 396 | assert(hdr.magic == AMX.MAGIC); 397 | codesize = this.codesize; 398 | code = this.code; 399 | data = this.buffer.slice(hdr.dat); 400 | hea = this.hea; 401 | stk = this.stk; 402 | reset_stk = stk; 403 | reset_hea = hea; 404 | alt = frm = pri = 0; 405 | var address; 406 | 407 | if(parseInt(index).toString() != index.toString()) { 408 | for(i = 0; i < this.publics.length; i++) { 409 | if(this.publics[i].name == index) { 410 | index = i; 411 | break; 412 | } 413 | } 414 | if(typeof index == "string") { 415 | throw new AMX.Error("Can't find public function" + index); 416 | } 417 | } 418 | 419 | this.error = new AMX.Error("AMX_ERR_NONE", ""); 420 | 421 | if(index == AMX_EXEC_MAIN) { 422 | if(hdr.cip < 0) { 423 | throw new AMX.Error("AMX_ERR_INDEX", ""); 424 | } 425 | cip = this.cip; 426 | } else if(index == -2) { 427 | frm = this.frm; 428 | stk = this.stk; 429 | hea = this.hea; 430 | pri = this.pri; 431 | alt = this.alt; 432 | reset_stk = this.reset_stk; 433 | reset_hea = this.reset_hea; 434 | cip = this.cip; 435 | } else if(index < 0) { 436 | throw new AMX.Error("AMX_ERR_INDEX", "index < 0"); 437 | } else { 438 | if(index >= (hdr.natives - hdr.publics) / hdr.defsize) { 439 | throw new AMX.Error("AMX_ERR_INDEX", ""); 440 | } 441 | 442 | cip = this.publics[index].address; 443 | 444 | //console.log("Cip at " + cip); 445 | } 446 | 447 | if(index != AMX_EXEC_CONT) { 448 | reset_stk += this.paramcount * AMX_CELL_SIZE; 449 | PUSH(this.paramcount * AMX_CELL_SIZE); 450 | this.paramcount = 0; 451 | PUSH(0); 452 | } 453 | 454 | function PUSH(v) { 455 | stk -= AMX_CELL_SIZE; 456 | data.writeInt32LE(v, stk); 457 | } 458 | 459 | function POP() { 460 | var ret = data.readInt32LE(stk); 461 | stk += AMX_CELL_SIZE; 462 | return ret; 463 | } 464 | 465 | function GETPARAM() { 466 | var param = code.readInt32LE(cip); 467 | cip += AMX_CELL_SIZE; 468 | return param; 469 | } 470 | 471 | function CHKMARGIN() { 472 | if(hea + 16 * AMX_CELL_SIZE > stk) { 473 | throw new AMX.Error("AMX_ERR_STACKERR"); 474 | } 475 | } 476 | 477 | function CHKSTACK() { 478 | if(stk > this.stp) { 479 | throw new AMX.Error("AMX_ERR_STACKLOW"); 480 | } 481 | } 482 | 483 | while(true) { 484 | op = code.readInt32LE(cip); 485 | cip += AMX_CELL_SIZE; 486 | //console.log("Instruction: " + AMX.OPCODES[op]); 487 | switch(op) { 488 | case OP_NONE: 489 | break; 490 | case OP_LOAD_PRI: 491 | pri = data.readInt32LE(GETPARAM()); 492 | break; 493 | case OP_LOAD_ALT: 494 | alt = data.readInt32LE(GETPARAM()); 495 | break; 496 | case OP_LOAD_S_PRI: 497 | pri = data.readInt32LE(frm + GETPARAM()); 498 | break; 499 | case OP_LOAD_S_ALT: 500 | alt = data.readInt32LE(frm + GETPARAM()); 501 | break; 502 | case OP_LREF_PRI: 503 | pri = data.readInt32LE(data.readInt32LE(GETPARAM())); 504 | break; 505 | case OP_LREF_ALT: 506 | alt = data.readInt32LE(data.readInt32LE(GETPARAM())); 507 | break; 508 | case OP_LREF_S_PRI: 509 | pri = data.readInt32LE(data.readInt32LE(frm + GETPARAM())); 510 | break; 511 | case OP_LREF_S_ALT: 512 | alt = data.readInt32LE(data.readInt32LE(frm + GETPARAM())); 513 | break; 514 | case OP_LOAD_I: 515 | if (pri >= hea && pri < stk || pri >= this.stp) { 516 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 517 | } 518 | pri = data.readInt32LE(pri); 519 | break; 520 | case OP_LODB_I: 521 | if (pri >= hea && pri < stk || pri >= this.stp) { 522 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 523 | } 524 | switch(GETPARAM()) { 525 | case 1: 526 | pri = data[pri]; 527 | break; 528 | case 2: 529 | pri = data.readUInt16LE(pri); 530 | break; 531 | case 4: 532 | pri = data.readInt32LE(pri); 533 | break; 534 | } 535 | break; 536 | case OP_CONST_PRI: 537 | pri = GETPARAM(); 538 | break; 539 | case OP_CONST_ALT: 540 | alt = GETPARAM(); 541 | break; 542 | case OP_ADDR_PRI: 543 | pri = GETPARAM() + frm; 544 | break; 545 | case OP_ADDR_ALT: 546 | alt = GETPARAM() + frm; 547 | break; 548 | case OP_STOR_PRI: 549 | data.writeInt32LE(pri, GETPARAM()); 550 | break; 551 | case OP_STOR_ALT: 552 | data.writeInt32LE(alt, GETPARAM()); 553 | break; 554 | case OP_STOR_S_PRI: 555 | data.writeInt32LE(pri, frm + GETPARAM()); 556 | break; 557 | case OP_STOR_S_ALT: 558 | data.writeInt32LE(alt, frm + GETPARAM()); 559 | break; 560 | case OP_SREF_PRI: 561 | data.writeInt32LE(pri, data.readInt32LE(GETPARAM())); 562 | break; 563 | case OP_SREF_ALT: 564 | data.writeInt32LE(alt, data.readInt32LE(GETPARAM())); 565 | break; 566 | case OP_SREF_S_PRI: 567 | data.writeInt32LE(pri, data.readInt32LE(frm + GETPARAM())); 568 | break; 569 | case OP_SREF_S_ALT: 570 | data.writeInt32LE(alt, data.readInt32LE(frm + GETPARAM())); 571 | break; 572 | case OP_STOR_I: 573 | if(alt >= hea && alt < stk || alt >= this.stp) { 574 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 575 | } 576 | data.writeInt32LE(pri, alt); 577 | break; 578 | case OP_STRB_I: 579 | if(alt >= hea && alt < stk || alt >= this.stp) { 580 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 581 | } 582 | switch(GETPARAM()) { 583 | case 1: 584 | data[alt] = pri & 0xFF; 585 | break; 586 | case 2: 587 | data.writeUInt16LE(pri & 0xFFFF, alt); 588 | break; 589 | case 4: 590 | data.writeInt32LE(pri, alt); 591 | break; 592 | } 593 | break; 594 | case OP_LIDX: 595 | offs = pri * AMX_CELL_SIZE + alt; 596 | if(offs >= hea && offs < stk || offs >= this.stp) { 597 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 598 | } 599 | pri = data.readInt32LE(offs); 600 | break; 601 | case OP_LIDX_B: 602 | offs = (pri << GETPARAM()) + alt; 603 | if(offs >= hea && offs < stk || offs >= this.stp) { 604 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 605 | } 606 | pri = data.readInt32LE(offs); 607 | break; 608 | case OP_IDXADDR: 609 | pri = pri * AMX_CELL_SIZE + alt; 610 | break; 611 | case OP_IDXADDR_B: 612 | pri = (pri << GETPARAM()) + alt; 613 | break; 614 | case OP_ALIGN_PRI: 615 | offs = GETPARAM(); 616 | if(offs < AMX_CELL_SIZE) { 617 | pri ^= AMX_CELL_SIZE - offs; 618 | } 619 | break; 620 | case OP_ALIGN_ALT: 621 | offs = GETPARAM() 622 | if(offs < AMX_CELL_SIZE) { 623 | alt ^= AMX_CELL_SIZE - offs; 624 | } 625 | break; 626 | case OP_LCTRL: 627 | switch(GETPARAM()) { 628 | case 0: 629 | pri = hdr.cod; 630 | break; 631 | case 1: 632 | pri = hdr.dat; 633 | break; 634 | case 2: 635 | pri = hea; 636 | break; 637 | case 3: 638 | pri = this.stp; 639 | break; 640 | case 4: 641 | pri = stk; 642 | break; 643 | case 5: 644 | pri = frm; 645 | break; 646 | case 6: 647 | pri = cip; 648 | break; 649 | } 650 | break; 651 | case OP_SCTRL: 652 | switch(GETPARAM()) { 653 | case 0: 654 | case 1: 655 | break; 656 | case 2: 657 | hea = pri; 658 | break; 659 | case 3: 660 | break; 661 | case 4: 662 | stk = pri; 663 | break; 664 | case 5: 665 | frm = pri; 666 | case 6: 667 | cip = pri; 668 | break; 669 | } 670 | break; 671 | case OP_MOVE_PRI: 672 | pri = alt; 673 | break; 674 | case OP_MOVE_ALT: 675 | alt = pri; 676 | break; 677 | case OP_XCHG: 678 | offs = pri; 679 | pri = alt; 680 | alt = offs; 681 | break; 682 | case OP_PUSH_PRI: 683 | PUSH(pri); 684 | break; 685 | case OP_PUSH_ALT: 686 | PUSH(alt); 687 | break; 688 | case OP_PUSH_C: 689 | PUSH(GETPARAM()); 690 | break; 691 | case OP_PUSH_R: 692 | offs = GETPARAM(); 693 | while(offs--) { 694 | PUSH(pri); 695 | } 696 | break; 697 | case OP_PUSH: 698 | PUSH(data.readInt32LE(GETPARAM())); 699 | break; 700 | case OP_PUSH_S: 701 | PUSH(data.readInt32LE(frm + GETPARAM())); 702 | break; 703 | case OP_POP_PRI: 704 | pri = POP(); 705 | break; 706 | case OP_POP_ALT: 707 | alt = POP(); 708 | break; 709 | case OP_STACK: 710 | alt = stk; 711 | stk += GETPARAM(); 712 | CHKMARGIN(); 713 | CHKSTACK(); 714 | break; 715 | case OP_HEAP: 716 | alt = hea; 717 | hea += GETPARAM(); 718 | CHKMARGIN(); 719 | CHKSTACK(); 720 | break; 721 | case OP_PROC: 722 | PUSH(frm); 723 | frm = stk; 724 | CHKMARGIN(); 725 | break; 726 | case OP_RET: 727 | frm = POP(); 728 | offs = POP(); 729 | if(offs >= codesize) { 730 | throw new AMX.Error("AMX_ERR_MEMACCESS", "offs >= codesize") 731 | } 732 | cip = offs; 733 | break; 734 | case OP_RETN: 735 | frm = POP(); 736 | offs = POP(); 737 | if(offs >= codesize) { 738 | throw new AMX.Error("AMX_ERR_MEMACCESS", "offs >= codesize") 739 | } 740 | cip = offs; 741 | stk += data.readInt32LE(stk) + AMX_CELL_SIZE; 742 | this.stk = stk; 743 | break; 744 | case OP_CALL: 745 | PUSH(cip + AMX_CELL_SIZE); 746 | cip = code.readInt32LE(cip); 747 | break; 748 | case OP_CALL_PRI: 749 | PUSH(cip); 750 | cip = pri; 751 | case OP_JUMP: 752 | cip = code.readInt32LE(cip); 753 | break; 754 | case OP_JREL: 755 | cip += code.readInt32LE(cip) + AMX_CELL_SIZE; 756 | break; 757 | case OP_JZER: 758 | if(pri == 0) { 759 | cip = code.readInt32LE(cip); 760 | } else { 761 | cip += AMX_CELL_SIZE; 762 | } 763 | break; 764 | case OP_JNZ: 765 | if(pri != 0) { 766 | cip = code.readInt32LE(cip); 767 | } else { 768 | cip += AMX_CELL_SIZE; 769 | } 770 | break; 771 | case OP_JEQ: 772 | if(pri == alt) { 773 | cip = code.readInt32LE(cip); 774 | } else { 775 | cip += AMX_CELL_SIZE; 776 | } 777 | break; 778 | case OP_JNEQ: 779 | if(pri != alt) { 780 | cip = code.readInt32LE(cip); 781 | } else { 782 | cip += AMX_CELL_SIZE; 783 | } 784 | break; 785 | case OP_JLESS: 786 | if((pri >>> 0) < (alt >>> 0)) { 787 | cip = code.readInt32LE(cip); 788 | } else { 789 | cip += AMX_CELL_SIZE; 790 | } 791 | break; 792 | case OP_JLEQ: 793 | if((pri >>> 0) <= (alt >>> 0)) { 794 | cip = code.readInt32LE(cip); 795 | } else { 796 | cip += AMX_CELL_SIZE; 797 | } 798 | break; 799 | case OP_JGRTR: 800 | if((pri >>> 0) > (alt >>> 0)) { 801 | cip = code.readInt32LE(cip); 802 | } else { 803 | cip += AMX_CELL_SIZE; 804 | } 805 | break; 806 | case OP_JGEQ: 807 | if((pri >>> 0) >= (alt >>> 0)) { 808 | cip = code.readInt32LE(cip); 809 | } else { 810 | cip += AMX_CELL_SIZE; 811 | } 812 | break; 813 | case OP_JSLESS: 814 | if(pri < alt) { 815 | cip = code.readInt32LE(cip); 816 | } else { 817 | cip += AMX_CELL_SIZE; 818 | } 819 | break; 820 | case OP_JSLEQ: 821 | if(pri <= alt) { 822 | cip = code.readInt32LE(cip); 823 | } else { 824 | cip += AMX_CELL_SIZE; 825 | } 826 | break; 827 | case OP_JSGRTR: 828 | if(pri > alt) { 829 | cip = code.readInt32LE(cip); 830 | } else { 831 | cip += AMX_CELL_SIZE; 832 | } 833 | break; 834 | case OP_JSGEQ: 835 | if(pri >= alt) { 836 | cip = code.readInt32LE(cip); 837 | } else { 838 | cip += AMX_CELL_SIZE; 839 | } 840 | break; 841 | case OP_SHL: 842 | pri <<= alt; 843 | break; 844 | case OP_SHR: 845 | pri >>>= alt; 846 | break; 847 | case OP_SSHR: 848 | pri >>= alt; 849 | break; 850 | case OP_SHL_C_PRI: 851 | pri <<= GETPARAM(); 852 | break; 853 | case OP_SHL_C_ALT: 854 | alt <<= GETPARAM(); 855 | break; 856 | case OP_SHR_C_PRI: 857 | pri >>>= GETPARAM(); 858 | break; 859 | case OP_SHR_C_ALT: 860 | alt >>>= GETPARAM(); 861 | break; 862 | case OP_SMUL: 863 | pri = (pri * alt) >> 0; 864 | break; 865 | case OP_SDIV: 866 | if(alt == 0) { 867 | throw new AMX.Error("AMX_ERR_DIVIDE"); 868 | } 869 | offs = (pri % alt + alt) % alt; 870 | pri = (pri - offs) / alt; 871 | alt = offs; 872 | break; 873 | case OP_SDIV_ALT: 874 | if(pri == 0) { 875 | throw new AMX.Error("AMX_ERR_DIVIDE"); 876 | } 877 | offs = (alt % pri + pri) % pri; 878 | pri = (alt - offs) / pri; 879 | alt = offs; 880 | break; 881 | case OP_UMUL: 882 | pri = (((pri >>> 0) * (alt >>> 0)) >>> 0) >> 0; 883 | break; 884 | case OP_UDIV: 885 | if(alt == 0) { 886 | throw new AMX.Error("AMX_ERR_DIVIDE"); 887 | } 888 | offs = (((pri >>> 0) % (alt >>> 0)) >>> 0) >> 0; 889 | pri = (((pri >>> 0) / (alt >>> 0)) >>> 0) >> 0; 890 | alt = offs; 891 | break; 892 | case OP_UDIV_ALT: 893 | if(pri == 0) { 894 | throw new AMX.Error("AMX_ERR_DIVIDE"); 895 | } 896 | offs = (((alt >>> 0) % (pri >>> 0)) >>> 0) >> 0; 897 | pri = (((alt >>> 0) / (pri >>> 0)) >>> 0) >> 0; 898 | alt = offs; 899 | break; 900 | case OP_ADD: 901 | pri = (pri + alt) >> 0; 902 | break; 903 | case OP_SUB: 904 | pri = (pri - alt) >> 0; 905 | break; 906 | case OP_SUB_ALT: 907 | pri = (alt - pri) >> 0; 908 | break; 909 | case OP_AND: 910 | pri &= alt; 911 | break; 912 | case OP_OR: 913 | pri |= alt; 914 | break; 915 | case OP_XOR: 916 | pri ^= alt; 917 | break; 918 | case OP_NOT: 919 | pri = !pri >> 0; 920 | break; 921 | case OP_NEG: 922 | pri = -pri; 923 | break; 924 | case OP_INVERT: 925 | pri = ~pri; 926 | break; 927 | case OP_ADD_C: 928 | pri = (pri + GETPARAM()) >> 0; 929 | break; 930 | case OP_SMUL_C: 931 | pri = (pri * GETPARAM()) >> 0; 932 | break; 933 | case OP_ZERO_PRI: 934 | pri = 0; 935 | break; 936 | case OP_ZERO_ALT: 937 | alt = 0; 938 | break; 939 | case OP_ZERO: 940 | data.writeInt32LE(0, GETPARAM()); 941 | break; 942 | case OP_ZERO_S: 943 | data.writeInt32LE(0, frm + GETPARAM()); 944 | break; 945 | case OP_SIGN_PRI: 946 | if((pri & 0xFF) >= 0x80) { 947 | pri |= ~0xFF; 948 | } 949 | break; 950 | case OP_SIGN_ALT: 951 | if((alt & 0xFF) >= 0x80) { 952 | alt |= ~0xFF; 953 | } 954 | break; 955 | case OP_EQ: 956 | pri = (pri == alt) >> 0; 957 | break; 958 | case OP_NEQ: 959 | pri = (pri != alt) >> 0; 960 | break; 961 | case OP_LESS: 962 | pri = ((pri >>> 0) < (alt >>> 0)) >> 0; 963 | break; 964 | case OP_LEQ: 965 | pri = ((pri >>> 0) <= (alt >>> 0)) >> 0; 966 | break; 967 | case OP_GRTR: 968 | pri = ((pri >>> 0) > (alt >>> 0)) >> 0; 969 | break; 970 | case OP_GEQ: 971 | pri = ((pri >>> 0) >= (alt >>> 0)) >> 0; 972 | break; 973 | case OP_SLESS: 974 | pri = (pri < alt) >> 0; 975 | break; 976 | case OP_SLEQ: 977 | pri = (pri <= alt) >> 0; 978 | break; 979 | case OP_SGRTR: 980 | pri = (pri > alt) >> 0; 981 | break; 982 | case OP_SGEQ: 983 | pri = (pri >= alt) >> 0; 984 | break; 985 | case OP_EQ_C_PRI: 986 | pri = (pri == GETPARAM()) >> 0; 987 | break; 988 | case OP_EQ_C_ALT: 989 | pri = (alt == GETPARAM()) >> 0; 990 | break; 991 | case OP_INC_PRI: 992 | pri = (pri + 1) >> 0; 993 | break; 994 | case OP_INC_ALT: 995 | alt = (alt + 1) >> 0; 996 | break; 997 | case OP_INC: 998 | offs = GETPARAM(); 999 | data.writeInt32LE((data.readInt32LE(offs) + 1) >> 0, offs); 1000 | break; 1001 | case OP_INC_S: 1002 | offs = GETPARAM() + frm; 1003 | data.writeInt32LE((data.readInt32LE(offs) + 1) >> 0, offs); 1004 | break; 1005 | case OP_INC_I: 1006 | data.writeInt32LE((data.readInt32LE(pri) + 1) >> 0, pri); 1007 | break; 1008 | case OP_DEC_PRI: 1009 | pri = (pri - 1) >> 0; 1010 | break; 1011 | case OP_DEC_ALT: 1012 | alt = (alt - 1) >> 0; 1013 | break; 1014 | case OP_DEC: 1015 | offs = GETPARAM(); 1016 | data.writeInt32LE((data.readInt32LE(offs) - 1) >> 0, offs); 1017 | break; 1018 | case OP_DEC_S: 1019 | offs = GETPARAM() + frm; 1020 | data.writeInt32LE((data.readInt32LE(offs) - 1) >> 0, offs); 1021 | break; 1022 | case OP_DEC_I: 1023 | data.writeInt32LE((data.readInt32LE(pri) -1) >> 0, pri); 1024 | break; 1025 | case OP_MOVS: 1026 | offs = GETPARAM(); 1027 | if(pri >= hea && pri < stk || pri >= this.stp) { 1028 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1029 | } 1030 | if((pri + offs) > hea && (pri + offs) < stk || (pri + offs) > this.stp) { 1031 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1032 | } 1033 | if(alt >= hea && alt < stk || alt >= this.stp) { 1034 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1035 | } 1036 | if ((alt + offs) > hea && (alt + offs) < stk || (alt + offs) > this.stp) { 1037 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1038 | } 1039 | data.copy(data, alt, pri, offs); 1040 | break; 1041 | case OP_CMPS: 1042 | offs = GETPARAM(); 1043 | if(pri >= hea && pri < stk || pri >= this.stp) { 1044 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1045 | } 1046 | if((pri + offs) > hea && (pri + offs) < stk || (pri + offs) > this.stp) { 1047 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1048 | } 1049 | if(alt >= hea && alt < stk || alt >= this.stp) { 1050 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1051 | } 1052 | if ((alt + offs) > hea && (alt + offs) < stk || (alt + offs) > this.stp) { 1053 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1054 | } 1055 | pri = memcmp(data, alt, data, pri, offs); 1056 | break; 1057 | case OP_FILL: 1058 | offs = GETPARAM(); 1059 | if(alt >= hea && alt < stk || alt >= this.stp) { 1060 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1061 | } 1062 | if ((alt + offs) > hea && (alt + offs) < stk || (alt + offs)>this.stp) { 1063 | throw new AMX.Error("AMX_ERR_MEMACCESS"); 1064 | } 1065 | for (i = alt; offs >= AMX_CELL_SIZE; i += AMX_CELL_SIZE, offs -= AMX_CELL_SIZE) { 1066 | data.writeInt32LE(pri, i); 1067 | } 1068 | break; 1069 | case OP_HALT: 1070 | offs = GETPARAM(); 1071 | this.frm = frm; 1072 | this.pri = pri; 1073 | this.alt = alt; 1074 | this.cip = cip; 1075 | this.stk = reset_stk; 1076 | this.hea = reset_hea; 1077 | return pri; 1078 | case OP_BOUNDS: 1079 | if((pri >>> 0) > (GETPARAM() >>> 0)) { 1080 | throw new AMX.Error("AMX_ERR_BOUNDS"); 1081 | } 1082 | break; 1083 | case OP_SYSREQ_PRI: 1084 | this.cip = cip; 1085 | this.hea = hea; 1086 | this.frm = frm; 1087 | this.stk = stk; 1088 | num = this.callback(pri, data.slice(stk)); 1089 | if(typeof num.pri == "number") { 1090 | pri = num.pri; 1091 | } 1092 | if(num.num != 0 /* AMX_ERR_NONE */) { 1093 | if(num.num == 12 /* AMX_ERR_SLEEP */) { 1094 | this.pri = pri; 1095 | this.alt = alt; 1096 | this.reset_stk = reset_stk; 1097 | this.reset_hea = reset_hea; 1098 | return; 1099 | } 1100 | this.reset_stk = reset_stk; 1101 | this.reset_hea = reset_hea; 1102 | return; 1103 | } 1104 | break; 1105 | case OP_SYSREQ_C: 1106 | offs = GETPARAM(); 1107 | this.cip = cip; 1108 | this.hea = hea; 1109 | this.frm = frm; 1110 | this.stk = stk; 1111 | num = this.callback(offs, data.slice(stk)); 1112 | if(typeof num.pri == "number") { 1113 | pri = num.pri; 1114 | } 1115 | if(num.num != 0 /* AMX_ERR_NONE */) { 1116 | if(num.num == 12 /* AMX_ERR_SLEEP */) { 1117 | this.pri = pri; 1118 | this.alt = alt; 1119 | this.reset_stk = reset_stk; 1120 | this.reset_hea = reset_hea; 1121 | return; 1122 | } 1123 | this.reset_stk = reset_stk; 1124 | this.reset_hea = reset_hea; 1125 | return; 1126 | } 1127 | break; 1128 | case OP_LINE: 1129 | GETPARAM(); 1130 | GETPARAM(); 1131 | break; 1132 | case OP_SYMBOL: 1133 | cip += GETPARAM(); 1134 | break; 1135 | case OP_SRANGE: 1136 | GETPARAM(); 1137 | GETPARAM(); 1138 | break; 1139 | case OP_SYMTAG: 1140 | GETPARAM(); 1141 | break; 1142 | case OP_JUMP_PRI: 1143 | cip = pri; 1144 | break; 1145 | case OP_SWITCH: 1146 | var cptr = cip + AMX_CELL_SIZE; 1147 | cip = code.readInt32LE(cptr + AMX_CELL_SIZE); 1148 | num = code.readInt32LE(cptr); 1149 | for(cptr += 2 * AMX_CELL_SIZE; num > 0 && code.readInt32LE(cptr) != pri; num--, cptr += 2 * AMX_CELL_SIZE) { 1150 | /* nothing */ 1151 | } 1152 | if(num > 0) { 1153 | cip = code.readInt32LE(cptr + AMX_CELL_SIZE); 1154 | } 1155 | break; 1156 | case OP_CASETBL: 1157 | throw new AMX.Error("Invalid opcode", "OP_CASETBL should not be in the token stream.") 1158 | case OP_SWAP_PRI: 1159 | offs = data.readInt32(stk); 1160 | data.writeInt32(pri, stk); 1161 | pri = offs; 1162 | break; 1163 | case OP_SWAP_ALT: 1164 | offs = data.readInt32(stk); 1165 | data.writeInt32(alt, stk); 1166 | alt = offs; 1167 | break; 1168 | case OP_PUSHADDR: 1169 | PUSH(frm + GETPARAM()); 1170 | break; 1171 | case OP_NOP: 1172 | break; 1173 | case OP_SYSREQ_D: 1174 | GETPARAM(); 1175 | throw new AMX.Error("SYSREQ_D not implemented"); 1176 | break; 1177 | case OP_SYMTAG: 1178 | break; 1179 | case OP_BREAK: 1180 | break; 1181 | default: 1182 | throw new AMX.Error("AMX_ERR_INVINSTR", "Unknown opcode"); 1183 | } 1184 | } 1185 | } 1186 | 1187 | AMX.prototype.exec2 = function(index) { 1188 | if(!this.jittedFunc) { 1189 | //console.log("JIT it first!"); 1190 | return; 1191 | } 1192 | function PUSH(v) { 1193 | stk -= AMX_CELL_SIZE; 1194 | data.writeInt32LE(v, stk); 1195 | } 1196 | var hdr; 1197 | var code, data; 1198 | var pri, alt, stk, frm, hea; 1199 | var reset_stk, reset_hea, cip; 1200 | var codesize; 1201 | var i; 1202 | var op; 1203 | var offs; 1204 | var num; 1205 | 1206 | if(typeof this.callback != "function") { 1207 | throw AMX.Error("AMX_ERR_CALLBACK", ""); 1208 | } 1209 | 1210 | hdr = this.base; 1211 | assert(hdr.magic == AMX.MAGIC); 1212 | codesize = this.codesize; 1213 | code = this.code; 1214 | data = this.buffer.slice(hdr.dat); 1215 | hea = this.hea; 1216 | stk = this.stk; 1217 | reset_stk = stk; 1218 | reset_hea = hea; 1219 | alt = frm = pri = 0; 1220 | var address; 1221 | 1222 | if(parseInt(index).toString() != index.toString()) { 1223 | for(i = 0; i < this.publics.length; i++) { 1224 | if(this.publics[i].name == index) { 1225 | index = i; 1226 | break; 1227 | } 1228 | } 1229 | if(typeof index == "string") { 1230 | throw new AMX.Error("Can't find public function" + index); 1231 | } 1232 | } 1233 | 1234 | this.error = new AMX.Error("AMX_ERR_NONE", ""); 1235 | 1236 | if(index == AMX_EXEC_MAIN) { 1237 | if(hdr.cip < 0) { 1238 | throw new AMX.Error("AMX_ERR_INDEX", ""); 1239 | } 1240 | cip = this.cip; 1241 | } else if(index == -2) { 1242 | frm = this.frm; 1243 | stk = this.stk; 1244 | hea = this.hea; 1245 | pri = this.pri; 1246 | alt = this.alt; 1247 | reset_stk = this.reset_stk; 1248 | reset_hea = this.reset_hea; 1249 | cip = this.cip; 1250 | } else if(index < 0) { 1251 | throw new AMX.Error("AMX_ERR_INDEX", "index < 0"); 1252 | } else { 1253 | if(index >= (hdr.natives - hdr.publics) / hdr.defsize) { 1254 | throw new AMX.Error("AMX_ERR_INDEX", ""); 1255 | } 1256 | 1257 | cip = this.publics[index].address; 1258 | 1259 | //console.log("Cip at " + cip); 1260 | } 1261 | 1262 | if(index != AMX_EXEC_CONT) { 1263 | reset_stk += this.paramcount * AMX_CELL_SIZE; 1264 | PUSH(this.paramcount * AMX_CELL_SIZE); 1265 | this.paramcount = 0; 1266 | PUSH(0); 1267 | } 1268 | 1269 | return this.jittedFunc(pri, alt, stk, frm, hea, reset_stk, reset_hea, cip, code, data, codesize); 1270 | } 1271 | 1272 | AMX.prototype.jit = function() { 1273 | var f = ""; 1274 | f += "var offs, num;"; 1275 | f += "const AMX_CELL_SIZE = " + AMX_CELL_SIZE + ";"; 1276 | f += "function PUSH(v) {stk -= AMX_CELL_SIZE;data.writeInt32LE(v, stk);}" 1277 | f += "function POP() {var ret = data.readInt32LE(stk);stk += AMX_CELL_SIZE;return ret;}"; 1278 | 1279 | f += 'function CHKMARGIN() {if(hea + 16 * AMX_CELL_SIZE > stk) {throw new AMX.Error("AMX_ERR_STACKERR");}}'; 1280 | 1281 | f += 'function CHKSTACK() {if(stk > this.stp) {throw new AMX.Error("AMX_ERR_STACKLOW");}}'; 1282 | 1283 | f += "w: while(true){\n"; 1284 | 1285 | f += "switch(cip) {\n"; 1286 | 1287 | var cip = 0; 1288 | var t; 1289 | function NEXT(n) { 1290 | if(!n) { 1291 | cip += AMX_CELL_SIZE; 1292 | } else { 1293 | cip += AMX_CELL_SIZE * n; 1294 | } 1295 | } 1296 | 1297 | function GETPARAM() { 1298 | cip += AMX_CELL_SIZE; 1299 | return this.buffer.readInt32LE(this.base.cod + cip); 1300 | } 1301 | 1302 | GETPARAM = GETPARAM.bind(this); 1303 | 1304 | var jumps = [0]; 1305 | 1306 | while(cip < this.codesize) { 1307 | var op = this.buffer.readInt32LE(this.base.cod + cip); 1308 | f += "\ncase " + cip + ":" + "/*" + AMX.OPCODES[op] + "*/" + "\n"; 1309 | switch(op) { 1310 | case OP_NONE: 1311 | break; 1312 | case OP_LOAD_PRI: 1313 | f += "pri = data.readInt32LE(" + GETPARAM() + ");"; 1314 | break; 1315 | case OP_LOAD_ALT: 1316 | f += "alt = data.readInt32LE(" + GETPARAM() + ")"; 1317 | break; 1318 | case OP_LOAD_S_PRI: 1319 | f += "pri = data.readInt32LE(frm + " + GETPARAM() + ");"; 1320 | break; 1321 | case OP_LOAD_S_ALT: 1322 | f += "alt = data.readInt32LE(frm + " + GETPARAM() + ");"; 1323 | break; 1324 | case OP_LREF_PRI: 1325 | f += "pri = data.readInt32LE(data.readInt32LE(" + GETPARAM() + "));" 1326 | break; 1327 | case OP_LREF_ALT: 1328 | f += "alt = data.readInt32LE(data.readInt32LE(" + GETPARAM() + "));"; 1329 | break; 1330 | case OP_LREF_S_PRI: 1331 | f += "pri = data.readInt32LE(data.readInt32LE(frm + " + GETPARAM() + "));"; 1332 | break; 1333 | case OP_LREF_S_ALT: 1334 | f += "alt = data.readInt32LE(data.readInt32LE(frm + " + GETPARAM()+ "));"; 1335 | break; 1336 | case OP_HALT: 1337 | f += "offs = " + GETPARAM() + ";" + 1338 | "this.frm = frm;" + 1339 | "this.pri = pri;" + 1340 | "this.alt = alt;" + 1341 | "this.cip = " + (cip + AMX_CELL_SIZE) + ";" + 1342 | "this.stk = reset_stk;" + 1343 | "this.hea = reset_hea;" + 1344 | "return pri;" 1345 | break; 1346 | case OP_RETN: 1347 | f += "frm = POP();" + 1348 | "offs = POP();" + 1349 | "if(offs >= codesize) {" + 1350 | ' throw new AMX.Error("AMX_ERR_MEMACCESS", "offs >= codesize");' + 1351 | "}" + 1352 | "cip = offs;" + 1353 | "stk += data.readInt32LE(stk) + AMX_CELL_SIZE;" + 1354 | "this.stk = stk;" + 1355 | //"//console.log('At " + cip + ", jumping to ' + cip + '.');" + 1356 | "break;"; 1357 | break; 1358 | case OP_STACK: 1359 | f += "alt = stk;" + 1360 | "stk += " + GETPARAM() + ";" + 1361 | "CHKMARGIN();" + 1362 | "CHKSTACK();"; 1363 | break; 1364 | case OP_SUB_ALT: 1365 | f += "pri = (alt - pri) >> 0;"; 1366 | break; 1367 | case OP_BREAK: 1368 | break; 1369 | case OP_STOR_S_PRI: 1370 | f += "data.writeInt32LE(pri, frm + " + GETPARAM() + ");"; 1371 | break; 1372 | case OP_SYSREQ_C: 1373 | f += "offs = " + GETPARAM() + ";" + 1374 | "this.cip = " + (cip + AMX_CELL_SIZE) + ";" + 1375 | "this.hea = hea;" + 1376 | "this.frm = frm; " + 1377 | "this.stk = stk;" + 1378 | "num = this.callback(offs, data.slice(stk));" + 1379 | 'if(typeof num.pri == "number") {' + 1380 | " pri = num.pri;" + 1381 | "}" + 1382 | "if(num.num != 0 /* AMX_ERR_NONE */) {" + 1383 | " if(num.num == 12 /* AMX_ERR_SLEEP */) {" + 1384 | " this.pri = pri;" + 1385 | " this.alt = alt;" + 1386 | " this.reset_stk = reset_stk;" + 1387 | " this.reset_hea = reset_hea;" + 1388 | " return;" + 1389 | " }" + 1390 | " this.reset_stk = reset_stk;" + 1391 | " this.reset_hea = reset_hea;" + 1392 | " return;" + 1393 | "}"; 1394 | break; 1395 | case OP_PUSH_C: 1396 | f += "PUSH(" + GETPARAM() + ");"; 1397 | break; 1398 | case OP_JSGEQ: 1399 | t = GETPARAM(); 1400 | jumps.push(t); 1401 | f += "if(pri >= alt) {" + 1402 | " cip = " + t + ";" + 1403 | //"//console.log('At " + (cip - AMX_CELL_SIZE) + ", jumping to ' + cip + '.');" + 1404 | "break;" + 1405 | "}"; 1406 | break; 1407 | case OP_CONST_ALT: 1408 | f += "alt = " + GETPARAM() + ";"; 1409 | break; 1410 | case OP_INC_S: 1411 | t = GETPARAM(); 1412 | f += "data.writeInt32LE((data.readInt32LE(" + t + " + frm) + 1) >> 0, " + t + " + frm);"; 1413 | break; 1414 | case OP_JUMP: 1415 | t = GETPARAM(); 1416 | jumps.push(t); 1417 | f += "cip = " + t + ";" + 1418 | "break;"; 1419 | break; 1420 | case OP_PROC: 1421 | jumps.push(cip); 1422 | f += "PUSH(frm);" + 1423 | "frm = stk;" + 1424 | "CHKMARGIN();"; 1425 | break; 1426 | case OP_CALL: 1427 | t = cip + AMX_CELL_SIZE * 2; 1428 | jumps.push(t); 1429 | f += "PUSH(" + t + ");" 1430 | t = GETPARAM(); 1431 | jumps.push(t); 1432 | f += "cip = " + t + ";" + 1433 | "break;"; 1434 | break; 1435 | case OP_ADD_C: 1436 | f += "pri = (pri + " + GETPARAM() + ") >> 0;"; 1437 | break; 1438 | case OP_PUSH_PRI: 1439 | f += "PUSH(pri);"; 1440 | break; 1441 | case OP_POP_ALT: 1442 | f += "alt = POP();"; 1443 | break; 1444 | case OP_ADD: 1445 | f += "pri = (pri + alt) >> 0;"; 1446 | break; 1447 | case OP_JNZ: 1448 | t = GETPARAM(); 1449 | jumps.push(t); 1450 | f += "if(pri != 0) {" + 1451 | " cip = " + t + ";" + 1452 | "break;}"; 1453 | break; 1454 | case OP_ZERO_PRI: 1455 | f += "pri = 0;"; 1456 | break; 1457 | case OP_JSLEQ: 1458 | t = GETPARAM(); 1459 | jumps.push(t); 1460 | f += "if(pri <= alt) {" + 1461 | " cip = " + t + ";" + 1462 | "break;}"; 1463 | break; 1464 | default: 1465 | throw new AMX.Error("Unknown opcode", AMX.OPCODES[op]); 1466 | } 1467 | NEXT(); 1468 | } 1469 | 1470 | f += "\ndefault: //console.log('Unknown cip: ' + cip); return;}}"; 1471 | 1472 | var r = /case (\d+):/g; 1473 | var repl = function(m, n) { 1474 | if(jumps.indexOf(Number(n)) == -1) { 1475 | return ""; 1476 | } else { 1477 | return m; 1478 | } 1479 | }; 1480 | 1481 | // remove any unused cases 1482 | f = f.replace(r, repl); 1483 | 1484 | this.jittedFunc = new Function("pri, alt, stk, frm, hea, reset_stk, reset_hea, cip, code, data, codesize", 1485 | f); 1486 | 1487 | } 1488 | 1489 | function memcmp(buffer1, offset1, buffer2, offset2, length) { 1490 | for(var i = 0; i < length; i++, offset1++, offset2++) { 1491 | if(buffer1[offset1] != buffer2[offset2]) { 1492 | return buffer1[offset] - buffer2[offset]; 1493 | } 1494 | } 1495 | return 0; 1496 | } 1497 | 1498 | AMX.prototype.callback = function(pri, stk) { 1499 | var name = this.natives[pri].name; 1500 | if(typeof this.callbacks[name] == "function") { 1501 | pri = this.callbacks[name](stk); 1502 | } else { 1503 | //console.log("Native function " + name + " was called with " + stk.readInt32LE(0) + " arguments, but alas, it is not defined."); 1504 | } 1505 | 1506 | return { 1507 | num: 0, 1508 | pri: pri 1509 | }; 1510 | } 1511 | 1512 | function expand(code, codesize, memsize) { 1513 | var c; 1514 | var spare = []; 1515 | for(var i = 0; i < AMX_COMPACTMARGIN; i++) { 1516 | spare[i] = { 1517 | memloc: 0, 1518 | c: 0 1519 | }; 1520 | } 1521 | var sh = 0, st = 0, sc = 0; 1522 | var shift = 0; 1523 | assert(memsize % AMX_CELL_SIZE == 0); 1524 | while(codesize > 0) { 1525 | c = 0; 1526 | shift = 0; 1527 | do { 1528 | codesize--; 1529 | assert(shift < 8 * AMX_CELL_SIZE); 1530 | assert(shift > 0 || (code[codesize] & 0x80) == 0); 1531 | c |= (code[codesize] & 0x7f) << shift; 1532 | shift += 7; 1533 | } while(codesize > 0 && (code[codesize - 1] & 0x80) != 0); 1534 | if((code[codesize] & 0x40) != 0) { 1535 | while(shift < 8 * AMX_CELL_SIZE) { 1536 | c |= 0xFF << shift; 1537 | shift += 8; 1538 | } 1539 | } 1540 | while(sc && spare[sh].memloc > codesize) { 1541 | code.writeInt32LE(spare[sh].c, spare[sh].memloc); 1542 | sh = (sh + 1) % AMX_COMPACTMARGIN; 1543 | sc--; 1544 | } 1545 | memsize -= AMX_CELL_SIZE; 1546 | assert(memsize >= 0); 1547 | if((memsize > codesize) || ((memsize == codesize) && (memsize == 0))) { 1548 | code.writeInt32LE(c, memsize); 1549 | } else { 1550 | assert(sc < AMX_COMPACTMARGIN); 1551 | spare[st].memloc = memsize; 1552 | spare[st].c = c; 1553 | st = (st + 1) % AMX_COMPACTMARGIN; 1554 | sc++; 1555 | } 1556 | } 1557 | assert(memsize == 0); 1558 | } 1559 | 1560 | AMX.Error = function(amxError, elaboration) { 1561 | //console.log(amxError); 1562 | //console.log(elaboration); 1563 | Error.call(this, amxError + ": " + elaboration); 1564 | } 1565 | 1566 | AMX.Error.prototype = new Error(); 1567 | 1568 | 1569 | 1570 | AMX.fromFile = function(file, callback) { 1571 | fs.open(file, "r", function(err, fd) { 1572 | if(err) { 1573 | callback(err); 1574 | return; 1575 | } 1576 | var buffer = new Buffer(AMXHeader.BYTE_SIZE); 1577 | fs.read(fd, buffer, 0, AMXHeader.BYTE_SIZE, 0, function(err, bytesRead, buffer) { 1578 | if(err) { 1579 | callback(err); 1580 | return; 1581 | } 1582 | if(bytesRead < AMXHeader.BYTE_SIZE) { 1583 | fs.close(fd); 1584 | callback(new Error("File size is less than AMX header size!")); 1585 | return; 1586 | } 1587 | var header = new AMXHeader(buffer); 1588 | for(var k in header) { 1589 | //console.log(k + ": " + header[k]); 1590 | } 1591 | var amxBuffer = new Buffer(header.stp); 1592 | fs.read(fd, amxBuffer, 0, header.size, 0, function(err, bytesRead, buffer) { 1593 | if(err) { 1594 | callback(err); 1595 | return; 1596 | } 1597 | if(bytesRead < header.size) { 1598 | fs.close(fd); 1599 | callback(new Error("File size is less than what AMX header specifies!")); 1600 | return; 1601 | } 1602 | callback(void(0), AMX.init(amxBuffer)); 1603 | }); 1604 | }); 1605 | }); 1606 | } 1607 | 1608 | function FuncStub(amx, offset, index) { 1609 | var name = ""; 1610 | var nameofs = 0; 1611 | if(amx.base.defsize == FuncStub.SIZEOF_FUNCSTUBNT) { 1612 | nameofs = amx.buffer.readInt32LE(offset + index * FuncStub.SIZEOF_FUNCSTUBNT + 4); 1613 | } else { 1614 | nameofs = offset + index * FuncStub.SIZEOF_FUNCSTUB + 4; 1615 | } 1616 | for(var c = amx.buffer[nameofs]; c; c = amx.buffer[++nameofs]) { 1617 | name += String.fromCharCode(c); 1618 | } 1619 | this.name = name; 1620 | this.buffer = amx.buffer.slice(offset + index * amx.base.defsize); 1621 | this.index = index; 1622 | } 1623 | 1624 | FuncStub.SIZEOF_FUNCSTUB = 20; 1625 | FuncStub.SIZEOF_FUNCSTUBNT = 8; 1626 | 1627 | Object.defineProperty(FuncStub.prototype, "address", { 1628 | get: function() { 1629 | return this.buffer.readUInt32LE(0); 1630 | }, 1631 | set: function(v) { 1632 | this.buffer.writeUInt32LE(v, 0); 1633 | }, 1634 | enumerable: true, 1635 | configurable: false 1636 | }); 1637 | 1638 | 1639 | 1640 | 1641 | exports.AMX = AMX; 1642 | exports.AMXHeader = AMXHeader; --------------------------------------------------------------------------------