-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtcp.cpp
More file actions
122 lines (105 loc) · 2.28 KB
/
tcp.cpp
File metadata and controls
122 lines (105 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "tcp.hpp"
wxConnectionBase* TCPClient::OnMakeConnection()
{
return new TCPConnection;
}
TCPClient::TCPClient(wxString _nick)
{
nick = _nick;
}
TCPClient::~TCPClient()
{
if( conn != 0)conn->Disconnect();
delete conn;
}
void TCPClient::SetChatbox(wxTextCtrl* _chatbox)
{
conn->SetChatbox(_chatbox);
}
void TCPClient::SetNicklist(wxListBox* _nicklist)
{
conn->SetNicklist(_nicklist);
}
TCPConnection* TCPClient::GetConn()
{
return conn;
}
wxConnectionBase* TCPClient::Connect()
{
wxString topic = "Logon";
topic += nick;
conn = (TCPConnection*)MakeConnection("192.168.178.254", "11111", topic.c_str());
return conn;
}
bool TCPConnection::OnAdvise(const wxString& topic, const wxString& item, char* data, int size, wxIPCFormat format)
{
if( item == "message")
{
wxString msg = data;
msg = msg.substr(0, size);
msg += "\n";
//msg[msg.size()-1] = '\n';
//msg += "\0";
chatbox->AppendText(msg);
}
else if( item == "logon")
{
wxTextAttr def = chatbox->GetDefaultStyle();
wxTextAttr temp;
//temp.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
temp.SetFont(*wxITALIC_FONT);
//wxTextAttr temp(*wxGREEN, wxNullColour, *wxITALIC_FONT);
chatbox->SetDefaultStyle(temp);
//chatbox->SetDefaultStyle(wxTextAttr(*wxGREEN, wxNullColour, *wxITALIC_FONT));
wxString msg = data;
msg = msg.substr(0, size);
msg += "\n";
chatbox->AppendText(msg);
UpdateNicklist();
chatbox->SetDefaultStyle(def);
}
else if( item == "logoff")
{
wxTextAttr def = chatbox->GetDefaultStyle();
wxTextAttr temp;
//temp.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
temp.SetFont(*wxITALIC_FONT);
chatbox->SetDefaultStyle(temp);
wxString msg = data;
msg = msg.substr(0, size);
msg += "\n";
chatbox->AppendText(msg);
UpdateNicklist();
chatbox->SetDefaultStyle(def);
}
return true;
}
void TCPConnection::SetChatbox(wxTextCtrl* _chatbox)
{
chatbox = _chatbox;
}
void TCPConnection::SetNicklist(wxListBox* _nicklist)
{
nicklist = _nicklist;
}
void TCPConnection::UpdateNicklist()
{
nicklist->Clear();
//int anz = 0;
wxString nicks = Request("nicklist", 0);
wxString next = "";
for( size_t n = 0; n < nicks.size(); n++)
{
if( nicks[n] == '\n')
{
nicklist->Append(next);
next.Clear();
}
else
{
next += nicks[n];
}
}
if( next != "")nicklist->Append(next);
next.Clear();
}