Advertisement
Guest User

FTP API RCON teszt

a guest
Nov 2nd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.80 KB | None | 0 0
  1. #include <a_samp>
  2. #include <ftp>
  3.  
  4. #if !defined unformat
  5.     #error "sscanf-ot töltsd le innen: https://github.com/maddinat0r/sscanf/releases"
  6. #endif
  7.  
  8. // Ha muszáj követni az elnevezéseket..
  9. #define Connect CreateFTP
  10. #define Disconnect DestroyFTP
  11. #define Download DownloadFTP
  12.  
  13. #define RCONCOMMAND:%1(%2) forward rconcmd_%1(%2);public rconcmd_%1(%2)
  14.  
  15. new RconFTP = INVALID_FTP_ID;
  16.  
  17. public OnFilterScriptExit() {
  18.     if (RconFTP != INVALID_FTP_ID) Disconnect(RconFTP);
  19.     return 1;
  20. }
  21.  
  22. public OnRconCommand(cmd[]) {
  23.     // kb. mint a zcmd féle parancskezelők csak összekókányolva
  24.     new command[32] = "rconcmd_", i = 0;
  25.     for (; cmd[i] && i < 32; i++) {
  26.         if (cmd[i] == ' ') {
  27.             if (funcidx(command) != (-1)) return CallLocalFunction(command, "s", cmd[++i]);
  28.             break;
  29.         }
  30.         command[i+8] = cmd[i];
  31.     }
  32.     if (funcidx(command) != (-1)) return CallLocalFunction(command, "s", "\1");
  33.     return 0;
  34. }
  35.  
  36. RCONCOMMAND:connect(params[]) {
  37.     if (RconFTP != INVALID_FTP_ID) {
  38.         printf("Már csatlakozva vagy egy ftp-hez!");
  39.         return 1;
  40.     }
  41.     new host[MAX_IPV4_LEN], port, user[24], pass[24];
  42.     // S(alap érték) opcionális string, I(érték) opcionális integer
  43.     if (unformat(params, "s[15]I(21)S()[24]S()[24]", host, port, user, pass)) {
  44.         print(" connect host [port] [user] [pass]");
  45.         return 1;
  46.     }
  47.     if (Connect(host, port, user, pass) == INVALID_FTP_ID) {
  48.         print("A kapcsolódás nem sikerült!");
  49.     }
  50.     return 1;
  51. }
  52.  
  53. RCONCOMMAND:disconnect(params[]) {
  54.     if (RconFTP == INVALID_FTP_ID) {
  55.         printf("Nem vagy csatlakozva ftp-hez!");
  56.         return 1;
  57.     }
  58.     Disconnect(RconFTP);
  59.     RconFTP = INVALID_FTP_ID;
  60.     return 1;
  61. }
  62.  
  63. RCONCOMMAND:download(params[]) {
  64.     if (RconFTP == INVALID_FTP_ID) {
  65.         printf("Nem vagy csatlakozva ftp-hez!");
  66.         return 1;
  67.     }
  68.     new file[MAX_PATH_LEN], saveAs[MAX_PATH_LEN];
  69.     if (unformat(params, "s[24]S()[24]", file, saveAs)) {
  70.         print(" download fájlnév [mentés mint]");
  71.         return 1;
  72.     }
  73.     if (strlen(saveAs) < 1) format(saveAs, MAX_PATH_LEN, file);
  74.     if (!Download(RconFTP, file, saveAs)) {
  75.         printf("Már folyamatban van egy letöltés");
  76.     }
  77.     return 1;
  78. }
  79.  
  80. public OnFileDownloaded(ftpId, file[], savedAs[]) {
  81.     printf("[ftp] %s letöltve ide: %s", file, savedAs);
  82.     return 1;
  83. }
  84.  
  85. public OnFTPFileNotFound(ftpId, file[]) {
  86.     printf("[ftp] %s nem található!", file);
  87.     return 1;
  88. }
  89.  
  90. public OnFTPConnected(ftpId) {
  91.     RconFTP = ftpId;
  92.     printf("[ftp] kapcsolat létrejött", ftpId);
  93.     return 1;
  94. }
  95.  
  96. new reasonString[][] = {
  97.     "No reason",
  98.     "Need account for login",
  99.     "Username okay, need password",
  100.     "Invalid username or password",
  101.     "Connection timed out",
  102.     "Not logged in"
  103. };
  104.  
  105. public OnFTPDisconnected(ftpId, reason) {
  106.     printf("[ftp] kapcsolat bontva (ok: %s)", reasonString[reason]);
  107.     RconFTP = INVALID_FTP_ID;
  108.     return 1;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement