Last change
on this file since 14 was 14, checked in by cheese, 9 years ago |
테스트 코드 추가
UI 모양 작업
채팅되는 상태까지 확인
|
File size:
1.6 KB
|
Line | |
---|
1 | #include <iostream>
|
---|
2 | #include <fstream>
|
---|
3 | #include <vector>
|
---|
4 | #include <sstream>
|
---|
5 |
|
---|
6 | #include "msgclnt.h"
|
---|
7 |
|
---|
8 | #define T(_expr) if ((_expr) == false) { std::cerr << c.getLastError() << std::endl; return -1; }
|
---|
9 | #define CIN(v) std::cout << #v << "\t: "; std::cin >> v
|
---|
10 |
|
---|
11 | std::string ip;
|
---|
12 | std::string port;
|
---|
13 | std::string id;
|
---|
14 | std::string pw;
|
---|
15 | std::string phone;
|
---|
16 | std::string sms;
|
---|
17 |
|
---|
18 | std::vector<std::string> toList;
|
---|
19 |
|
---|
20 | int showChat(SConversation & c)
|
---|
21 | {
|
---|
22 | std::cout << "[" << c.sessid << "][" << c.sensitive << "sec] "
|
---|
23 | << c.from << ": " << c.message
|
---|
24 | << std::endl;
|
---|
25 |
|
---|
26 | return 0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | int newChat(SOpenSession & o)
|
---|
30 | {
|
---|
31 | std::cout << "[" << o.sessid << "] => " << joinStrings(o.idList) << std::endl;
|
---|
32 | return 0;
|
---|
33 | }
|
---|
34 |
|
---|
35 | bool sendChat(chev & m)
|
---|
36 | {
|
---|
37 | SConversation c;
|
---|
38 | std::getline(std::cin, c.message);
|
---|
39 |
|
---|
40 | c.from = id;
|
---|
41 | c.sensitive = 0;
|
---|
42 | c.sessid = m.getSessionID(toList);
|
---|
43 |
|
---|
44 | return m.tell(c);
|
---|
45 | }
|
---|
46 |
|
---|
47 | int main(int argc, char ** argv)
|
---|
48 | {
|
---|
49 | // declaration
|
---|
50 | chev c;
|
---|
51 | SCallback cb;
|
---|
52 |
|
---|
53 | std::string ini = argv[1];
|
---|
54 | std::string tok, to;
|
---|
55 |
|
---|
56 | std::ifstream f(ini);
|
---|
57 |
|
---|
58 | std::getline(f, ip);
|
---|
59 | std::getline(f, port);
|
---|
60 | std::getline(f, id);
|
---|
61 | std::getline(f, pw);
|
---|
62 | std::getline(f, phone);
|
---|
63 | std::getline(f, to);
|
---|
64 |
|
---|
65 | std::istringstream is(to);
|
---|
66 | while (std::getline(is, tok, ','))
|
---|
67 | toList.push_back(tok);
|
---|
68 |
|
---|
69 | // init
|
---|
70 | cb.onListen = showChat;
|
---|
71 | cb.onOpenSession = newChat;
|
---|
72 |
|
---|
73 | // connect
|
---|
74 | T(c.connect(ip, atoi(port.c_str())));
|
---|
75 | T(c.listen(cb));
|
---|
76 | T(c.sms(phone));
|
---|
77 |
|
---|
78 | CIN(sms);
|
---|
79 | T(c.join(id, pw, sms));
|
---|
80 | std::getline(std::cin, sms);
|
---|
81 |
|
---|
82 | T(c.login(id, pw));
|
---|
83 |
|
---|
84 | while (true)
|
---|
85 | {
|
---|
86 | T(sendChat(c));
|
---|
87 | }
|
---|
88 |
|
---|
89 | return 0;
|
---|
90 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.