LordSputnik

When my C++ was so bad it was C

Mar 10th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.49 KB | None | 0 0
  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <commctrl.h>
  5. #include <winsock.h>
  6. #include <string>
  7. #include <iostream>
  8. #include "Bitmap.h"
  9. #include "Chat.h"
  10. #include "Main.h"
  11.  
  12. using namespace std;
  13.  
  14. // Variables
  15. HWND hChatTab;
  16. HWND hChatDlg;
  17. HWND hParent;
  18. HINSTANCE hInst;
  19. BOOL UnConnected;
  20. Bitmap * ChatBackGround;
  21. int ChatXPos, ChatYPos;
  22.  
  23. int CurrentChat;
  24. string Chat[MAX_NUM_CHATS];
  25. string texts;
  26. char* playerto;
  27. char messageto[200];
  28. char* newuser;
  29. char* newpass;
  30. char* newrace;
  31. char* newclass;
  32.  
  33. // Private Functions
  34. BOOL CALLBACK ChatDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
  35. void SendChat();
  36.  
  37. void CreateChat(HWND parentWnd, HINSTANCE hInstance, BOOL loginSkip)
  38. {
  39.      hParent = parentWnd;
  40.      hInst = hInstance;
  41.      UnConnected = loginSkip;
  42.      
  43.      InitCommonControls();
  44.      hChatTab = CreateWindow(WC_TABCONTROL, "", WS_CHILD|WS_VISIBLE|ES_LEFT,
  45.                     215, 567, 811, 201, parentWnd, NULL, hInstance, NULL);
  46.                    
  47.      TC_ITEM Item;
  48.      Item.mask = TCIF_TEXT;
  49.      Item.iImage = -1;
  50.      Item.pszText = "Local Chat";
  51.      TabCtrl_InsertItem(hChatTab, 0, &Item);
  52.      Item.pszText = "General Chat";
  53.      TabCtrl_InsertItem(hChatTab, 1, &Item);
  54.      Item.pszText = "Market Chat";
  55.      TabCtrl_InsertItem(hChatTab, 2, &Item);
  56.      Item.pszText = "Guild Chat";
  57.      TabCtrl_InsertItem(hChatTab, 3, &Item);
  58.      Item.pszText = "Admin Chat";
  59.      TabCtrl_InsertItem(hChatTab, 4, &Item);
  60.      
  61.  
  62.      RECT Rect;
  63.      GetWindowRect(hChatTab, &Rect);
  64.      ChatXPos = Rect.left;
  65.      ChatYPos = Rect.top;
  66.      
  67.      // Chat Dialog
  68.      hChatDlg = CreateDialog(hInstance, "ChatDlg", hChatTab, (DLGPROC)ChatDlgProc);
  69.      MoveWindow(hChatDlg, ChatXPos, ChatYPos+25, 811, 176, TRUE);
  70.      ShowWindow(hChatDlg, SW_SHOWNORMAL);
  71.      HDC hDC = GetDC(hChatDlg);
  72.      ChatBackGround = new Bitmap(hDC, IDB_CHAT_TAB, hInst);
  73.      ReleaseDC(hChatDlg, hDC);
  74.  
  75.      CurrentChat = CHAT_LOCAL;
  76.      SetChat(CHAT_LOCAL);
  77.  
  78.      
  79.      // Set Message of the Day
  80.      if(UnConnected)
  81.           Chat[CurrentChat] = "\t\t\tMessage of the Day: \"Gota slash 'em all\" \r\n";
  82.      else // if conncected to the server get motd from it
  83.           Chat[CurrentChat] = getmotd() + "\r\n";
  84.      Chat[1] = "\t\t\t\tGeneral Chat\r\n";
  85.      Chat[2] = "\t\t\t\tMarket Chat\r\n";
  86.      Chat[3] = "\t\t\t\tGuild Chat: Developers Guild\r\n";
  87.      Chat[4] = "\t\t\t\tWelcome to the admin chat.\r\n";
  88.      Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
  89.  
  90. }
  91.  
  92. void SetChat(int ChatNumber)
  93. {
  94.      CurrentChat = ChatNumber;
  95.      Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
  96.      
  97.      if(UnConnected)
  98.           return;
  99.  
  100.      Send("changetab");
  101.      small_delay();
  102.      switch(CurrentChat)
  103.      {
  104.           case CHAT_LOCAL:
  105.                Send("1");
  106.                break;
  107.           case CHAT_GENERAL:
  108.                Send("2");
  109.                break;
  110.           case CHAT_MARKET:
  111.                Send("3");
  112.                break;
  113.           case CHAT_GUILD:
  114.                Send("4");
  115.                break;
  116.           case CHAT_ADMIN:
  117.                Send("5");
  118.                break;
  119.           default:
  120.                Send("1");
  121.      }
  122.      small_delay();
  123. }
  124.  
  125. void UpdateChat()
  126. {
  127.      if(UnConnected)
  128.           return;
  129.      string newChat = getchat();
  130.      if (newChat == "wrongloc")
  131.           return;
  132.      Chat[CurrentChat] = Chat[CurrentChat] + "\r\n" + newChat;
  133.      Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
  134.  
  135. }
  136.  
  137. void DeleteChat()
  138. {
  139.      delete ChatBackGround;
  140. }
  141.  
  142. BOOL CALLBACK ChatDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
  143. {
  144.      switch(Message)
  145.      {
  146.           case WM_INITDIALOG:
  147.                {
  148.                     return TRUE;
  149.                }
  150.                break;
  151.           case WM_PAINT:
  152.                {
  153.                     PAINTSTRUCT PS;
  154.                     HDC hDC = BeginPaint(hDlg, &PS);
  155.                     ChatBackGround -> Draw(hDC, 0, 0);
  156.                     EndPaint(hDlg, &PS);
  157.                }
  158.                break;
  159.           case WM_COMMAND:
  160.                {
  161.                     if(LOWORD(wParam) == IDB_SEND_BTN)
  162.                          SendChat();
  163.                }
  164.                break;
  165.           case WM_KEYDOWN:
  166.                {
  167.                     if((UINT)wParam == VK_RETURN)
  168.                          SendChat();
  169.                    
  170.                }
  171.           case WM_DESTROY:
  172.                {
  173.                     PostQuitMessage(0);
  174.                }
  175.           default:
  176.                break;
  177.      }
  178.      return FALSE;
  179. }
  180.  
  181. void SendChat()
  182. {
  183.      char Text[200];
  184.      Edit_GetText(GetDlgItem(hChatDlg, IDE_INPUT), Text, 200);//64
  185.      Edit_SetText(GetDlgItem(hChatDlg, IDE_INPUT), "");
  186.      
  187.      if(UnConnected)
  188.      {
  189.           Chat[CurrentChat] = Chat[CurrentChat] + "\r\n" + Text;
  190.           Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
  191.           return;
  192.      }
  193.      if (Text[0] == '/')
  194.      {
  195.          if (Text[1] == 's' && Text[2] == 'h' && Text[3] == 'u' && Text[4] == 't'
  196.          && Text[5] == 'd' && Text[6] == 'o' && Text[7] == 'w' && Text[8] == 'n')
  197.          {
  198.              Send("/shutdown");
  199.          }
  200.          else if (Text[1] == 'c' && Text[2] == 'h' && Text[3] == 'a' && Text[4] == 'r'
  201.          && Text[5] == 'c' && Text[6] == 'r' && Text[7] == 'e' && Text[8] == 'a' &&
  202.           Text[9] == 't' && Text[10] == 'e')
  203.          {
  204.               texts = Text;
  205.               strtok (Text, " ");
  206.               newuser = strtok (NULL, " ");
  207.               newpass = strtok (NULL, " ");
  208.               newrace = strtok (NULL, " ");
  209.               newgender = strtok (NULL, " ");
  210.               newclass = strtok (NULL, " ");
  211.               newfirst = strtok (NULL, " ");
  212.               newsur = strtok (NULL, " ");
  213.               Send("charcreate");
  214.               Send( newuser);
  215.               Send( newpass);
  216.               Send( newrace);
  217.               Send( newgender);
  218.               Send( newclass);
  219.               Send( newfirst);
  220.               Send( newsur);
  221.          }        
  222.          else if (Text[1] == 'p' && Text[2] == 'm')
  223.          {
  224.               texts = Text;
  225.               strtok (Text, " ");
  226.               playerto = strtok (NULL, " ");
  227.               texts.copy(messageto,195,(5+ strlen(playerto)));
  228.               sendchat(3,messageto,playerto);
  229.          }
  230.  
  231.      }
  232.      else
  233.      sendchat(CurrentChat + 1, Text, NULL);
  234. }
Advertisement
Add Comment
Please, Sign In to add comment