Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define STRICT
- #include <windows.h>
- #include <windowsx.h>
- #include <commctrl.h>
- #include <winsock.h>
- #include <string>
- #include <iostream>
- #include "Bitmap.h"
- #include "Chat.h"
- #include "Main.h"
- using namespace std;
- // Variables
- HWND hChatTab;
- HWND hChatDlg;
- HWND hParent;
- HINSTANCE hInst;
- BOOL UnConnected;
- Bitmap * ChatBackGround;
- int ChatXPos, ChatYPos;
- int CurrentChat;
- string Chat[MAX_NUM_CHATS];
- string texts;
- char* playerto;
- char messageto[200];
- char* newuser;
- char* newpass;
- char* newrace;
- char* newclass;
- // Private Functions
- BOOL CALLBACK ChatDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
- void SendChat();
- void CreateChat(HWND parentWnd, HINSTANCE hInstance, BOOL loginSkip)
- {
- hParent = parentWnd;
- hInst = hInstance;
- UnConnected = loginSkip;
- InitCommonControls();
- hChatTab = CreateWindow(WC_TABCONTROL, "", WS_CHILD|WS_VISIBLE|ES_LEFT,
- 215, 567, 811, 201, parentWnd, NULL, hInstance, NULL);
- TC_ITEM Item;
- Item.mask = TCIF_TEXT;
- Item.iImage = -1;
- Item.pszText = "Local Chat";
- TabCtrl_InsertItem(hChatTab, 0, &Item);
- Item.pszText = "General Chat";
- TabCtrl_InsertItem(hChatTab, 1, &Item);
- Item.pszText = "Market Chat";
- TabCtrl_InsertItem(hChatTab, 2, &Item);
- Item.pszText = "Guild Chat";
- TabCtrl_InsertItem(hChatTab, 3, &Item);
- Item.pszText = "Admin Chat";
- TabCtrl_InsertItem(hChatTab, 4, &Item);
- RECT Rect;
- GetWindowRect(hChatTab, &Rect);
- ChatXPos = Rect.left;
- ChatYPos = Rect.top;
- // Chat Dialog
- hChatDlg = CreateDialog(hInstance, "ChatDlg", hChatTab, (DLGPROC)ChatDlgProc);
- MoveWindow(hChatDlg, ChatXPos, ChatYPos+25, 811, 176, TRUE);
- ShowWindow(hChatDlg, SW_SHOWNORMAL);
- HDC hDC = GetDC(hChatDlg);
- ChatBackGround = new Bitmap(hDC, IDB_CHAT_TAB, hInst);
- ReleaseDC(hChatDlg, hDC);
- CurrentChat = CHAT_LOCAL;
- SetChat(CHAT_LOCAL);
- // Set Message of the Day
- if(UnConnected)
- Chat[CurrentChat] = "\t\t\tMessage of the Day: \"Gota slash 'em all\" \r\n";
- else // if conncected to the server get motd from it
- Chat[CurrentChat] = getmotd() + "\r\n";
- Chat[1] = "\t\t\t\tGeneral Chat\r\n";
- Chat[2] = "\t\t\t\tMarket Chat\r\n";
- Chat[3] = "\t\t\t\tGuild Chat: Developers Guild\r\n";
- Chat[4] = "\t\t\t\tWelcome to the admin chat.\r\n";
- Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
- }
- void SetChat(int ChatNumber)
- {
- CurrentChat = ChatNumber;
- Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
- if(UnConnected)
- return;
- Send("changetab");
- small_delay();
- switch(CurrentChat)
- {
- case CHAT_LOCAL:
- Send("1");
- break;
- case CHAT_GENERAL:
- Send("2");
- break;
- case CHAT_MARKET:
- Send("3");
- break;
- case CHAT_GUILD:
- Send("4");
- break;
- case CHAT_ADMIN:
- Send("5");
- break;
- default:
- Send("1");
- }
- small_delay();
- }
- void UpdateChat()
- {
- if(UnConnected)
- return;
- string newChat = getchat();
- if (newChat == "wrongloc")
- return;
- Chat[CurrentChat] = Chat[CurrentChat] + "\r\n" + newChat;
- Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
- }
- void DeleteChat()
- {
- delete ChatBackGround;
- }
- BOOL CALLBACK ChatDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_INITDIALOG:
- {
- return TRUE;
- }
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT PS;
- HDC hDC = BeginPaint(hDlg, &PS);
- ChatBackGround -> Draw(hDC, 0, 0);
- EndPaint(hDlg, &PS);
- }
- break;
- case WM_COMMAND:
- {
- if(LOWORD(wParam) == IDB_SEND_BTN)
- SendChat();
- }
- break;
- case WM_KEYDOWN:
- {
- if((UINT)wParam == VK_RETURN)
- SendChat();
- }
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- }
- default:
- break;
- }
- return FALSE;
- }
- void SendChat()
- {
- char Text[200];
- Edit_GetText(GetDlgItem(hChatDlg, IDE_INPUT), Text, 200);//64
- Edit_SetText(GetDlgItem(hChatDlg, IDE_INPUT), "");
- if(UnConnected)
- {
- Chat[CurrentChat] = Chat[CurrentChat] + "\r\n" + Text;
- Edit_SetText(GetDlgItem(hChatDlg, IDE_CHAT), Chat[CurrentChat].c_str());
- return;
- }
- if (Text[0] == '/')
- {
- if (Text[1] == 's' && Text[2] == 'h' && Text[3] == 'u' && Text[4] == 't'
- && Text[5] == 'd' && Text[6] == 'o' && Text[7] == 'w' && Text[8] == 'n')
- {
- Send("/shutdown");
- }
- else if (Text[1] == 'c' && Text[2] == 'h' && Text[3] == 'a' && Text[4] == 'r'
- && Text[5] == 'c' && Text[6] == 'r' && Text[7] == 'e' && Text[8] == 'a' &&
- Text[9] == 't' && Text[10] == 'e')
- {
- texts = Text;
- strtok (Text, " ");
- newuser = strtok (NULL, " ");
- newpass = strtok (NULL, " ");
- newrace = strtok (NULL, " ");
- newgender = strtok (NULL, " ");
- newclass = strtok (NULL, " ");
- newfirst = strtok (NULL, " ");
- newsur = strtok (NULL, " ");
- Send("charcreate");
- Send( newuser);
- Send( newpass);
- Send( newrace);
- Send( newgender);
- Send( newclass);
- Send( newfirst);
- Send( newsur);
- }
- else if (Text[1] == 'p' && Text[2] == 'm')
- {
- texts = Text;
- strtok (Text, " ");
- playerto = strtok (NULL, " ");
- texts.copy(messageto,195,(5+ strlen(playerto)));
- sendchat(3,messageto,playerto);
- }
- }
- else
- sendchat(CurrentChat + 1, Text, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment