-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlPage.html
More file actions
367 lines (315 loc) · 15.8 KB
/
htmlPage.html
File metadata and controls
367 lines (315 loc) · 15.8 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>랜덤채팅</title>
<!-- 부트스트랩 사용-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<!-- socket.io.js파일-->
<script src="/socket.io/socket.io.js"></script>
<style>
body {
padding-top: 50px;
}
.chatDisabled {
display: none;
}
.chatabled {
display: block;
}
</style>
<script>
window.onload = function () {
var nickName = "";
var roomName = "";
var handle = null;
var socket = io.connect(); //웹소켓서버에 연결한다.
$("#nicknameBtn").on("click", function (event) {
var nicknameValue = $("input[name='nickname']").val();
nickName = nicknameValue;
socket.emit("nickNameCheck", { name: nicknameValue });
});
socket.on("nullError", function (result) {
alert(result);
});
socket.on("sameNameError", function (result) {
alert(result);
});
socket.on("nickNameCheckComplete", function () {
$("#chatBox").removeClass("chatDisabled").addClass("chatabled");
$("#nickNameForm").css("display", "none");
$("#sendMessage").hide(); $("#closing").hide();
$("#ramdomChatFindBtn").show();
$("#hobby").show();
clientCounting();
});
$("#hobby").on("click", function () {
$("#hobby_box").show();
});
$("#exit").on("click", function () {
$("#hobby_box").hide();
});
$("#ramdomChatFindBtn").on("click", function () {
$("#chat").html("");
$("#hobby_box").hide();
socket.emit("randomChatFindClick", { name: nickName });
})
socket.on("randomChatFindClickComplete", function gethobby() {
var obj_length = document.getElementsByName("hobby").length;
for (var i = 0; i < obj_length; i++) {
if (document.getElementsByName("hobby")[i].checked == true) {
alert(document.getElementsByName("hobby")[i].value + "이 선택됐습니다!");{
$("#chat").html("").append(document.getElementsByName("hobby")[i].value + " 상대를 찾고있습니다...</li>");
startFinding(); //실제로 대화상대찾기 시작
}
}
}
});
socket.on("randomChatFiningComplete", function gethobby(data) {
stopFinding(); //찾는걸 성공했으니 찾는걸 멈춰야댐.
var obj_length = document.getElementsByName("hobby").length;
for (var i = 0; i < obj_length; i++) {
if (document.getElementsByName("hobby")[i].checked == true) {
$("#chat").html("").append( "대화방에 입장했습니다!!</p><hr></li>");
$("#sendMessage").show(); $("#closing").show();
$("#ramdomChatFindBtn").hide();
$("#hobby").hide();
roomName = data;
}
}
});
$("#sendMessage").on("click", function () {
var content = $("#content").val();
var bad = ["욕설1", "욕설2", "욕설3", "바보"]; //금지단어
var ckc = [" ", ".", "-", "/", "*", "[", "]", "=", "#"]; //금지단어 사이에 입력되는 제거대상 문자 ex)바#보
var position;
for (i = 0; i < ckc.length; i++) {
position = content.indexOf(ckc[i]);
while (position != -1) {
content = content.replace(ckc[i], "");
position = content.indexOf(ckc[i]);
}
}
for (i = 0; i < bad.length; i++) {
if (content.match(bad[i])) {
alert(bad[i] + "란 단어는 사용하실수 없습니다.");
return;
}
}
console.log(content);
if (!content) {
alert("대화내용을 입력해주세요");
return;
}
var obj_length = document.getElementsByName("hobby").length;
for (var i = 0; i < obj_length; i++) {
if (document.getElementsByName("hobby")[i].checked == true) {
var str = "";
str += "<li>";
str += "<strong>"+ nickName + " " + "</strong>";
str += "(";
str += document.getElementsByName("hobby")[i].value;
str += ")";
str += "<p>" + content + "</p>";
str += "<hr>";
str += "</li>";
}
}
socket.emit("message", { roomName: roomName, data: str });
$("#content").val("");
$("#chat").scrollTop($("#chat")[0].scrollHeight);
});
socket.on("message", function press (data) {
$("#chat").append(data);
});
$("#closing").on("click", function () {
socket.emit("chatClosingBtn", { roomName: roomName });
})
socket.on("chatEnd", function (data) {
$("#chat").append("<li><p>대화방이 종료되었습니다</p><hr></li>");
$("#sendMessage").hide(); $("#closing").hide();
$("#ramdomChatFindBtn").show();
$("#hobby").show();
socket.emit("ChatClosing", { roomName: roomName });
});
socket.on("discWhileChat", function () {
socket.emit("chatClosingBtn", { roomName: roomName });
});
socket.on("clientsCount", function (data) {
$(".clientsCount").html(data);
})
function startFinding() {
if (handle == null) {
handle = setInterval(function () {
socket.emit("randomChatFining", { name: nickName });
}, 500);
}
}
function stopFinding() {
clearInterval(handle);
handle = null;
}
function clientCounting() {
setInterval(function () {
socket.emit("clientsCount");
}, 1500); //1.5초마다 clientsCount이벤트발생
}
}
type="application/javascript">
function getIP(json) {
document.write("My public IP address is: ", json.ip);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP">
</script>
</head>
<body>
<script>
(function () {
function resp() {
var arrUserIP = ['121.166.174.22']; // 차단할 아이피 입력
var json = JSON.parse(this.responseText);
for (var i = 0; i < arrUserIP.length; i++) {
if (arrUserIP[i] == json.ip) {
// 차단할 아이피 접속 시 보여줄 메시지(특정 주소로만 보내려면 아래 줄 삭제)
alert("당신은 접속이 차단되었습니다. 구글로 이동합니다.")
// 다른 곳으로 보낼 URL주소 입력
window.location.replace("https://google.com");
}
}
}
var request = new XMLHttpRequest();
request.addEventListener("load", resp);
request.open("GET", 'https://api.ipify.org?format=json');
request.send();
}());
</script>
<div class="container">
<div class="jumbotron">
<h1>1대1 랜덤채팅</h1>
<p>
대화방을 찾고 있는 상대방과 1대1로 채팅을 할 수 있는 사이트 입니다.<br>
닉네임을 입력하시고 확인버튼을 누르시면<br>
상대와 대화를 할 수 있는 채팅창을 활성화 하실 수 있습니다.
</p>
</div>
</div>
<div class="container" style="margin-top: 20px;" id="nickNameForm">
<div class="form-group form-inline">
<input type="text" name="nickname" class="form-control" maxlength="100" id="nickname"
placeholder="닉네임을 입력하세요..">
<button class="btn btn-primary" onclick="enter()" id="nicknameBtn">확인</button>
</div>
</div>
<div class="container chatDisabled" id="chatBox">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">채팅창<span class="pull-right">접속자 : <span class="clientsCount"></span>명</span>
</h1>
</div>
<div class="panel-body">
<ul class="chat list-unstyled" id="chat" style="height: 500px; overflow: auto;">
</ul>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-xs-9">
<input type="text" class="form-control" id="content" name="content" placeholder="대화내용을 입력하세요.."
maxlength="3000">
</div>
<div class="col-xs-3">
<button class="btn btn-primary" id="sendMessage">보내기</button>
<button class="btn btn-danger" id="closing">나가기</button>
<button class="btn btn-warning" id="hobby">랜덤채팅시작</button>
</div>
</div>
</div>
</div>
</div>
<div class="container hobby" id="hobby_box" style="display:none">
<div style="width: 800px">
<div class="panel panel-info">
<div class="panel-heading">
<h1 class="panel-title">취미 선택</h1>
</div>
<div class="panel-body">
<ul>
<div style="height: 200px;">
<form method="get" action="form-action.html">
<div style="width: 60px;">
<li>
<h4>문화</h4>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="책">
책</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="영화">
영화</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="드라마">
드라마</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="애니">
애니</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="방송">
방송</label>
</li>
</div>
<div style="width:80px; left:200px; bottom:200px; position: relative">
<li>
<h4>생활</h4>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="일상">
일상</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="애완동물">
애완동물</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="육아">
육아</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="패션">
패션</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="요리">
요리</label>
</li>
</div>
<div style="width: 60px; left:400px; bottom:403px; position: relative">
<li>
<h4>여가</h4>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="게임">
게임</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="자동차">
자동차</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="여행">
여행</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="맛집">
맛집</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="스포츠">
스포츠</label>
</li>
</div>
<div style="width: 60px; left:600px; bottom:605px; position: relative">
<li>
<h4>지식</h4>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="IT">
IT</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="건강">
건강</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="외국어">
외국어</label>
<label style="margin-top:5px;"><input type="radio" name="hobby" value="교육">
교육</label>
<label style="margin-top:5px;"><input type="radio" name="hooby" value="의학">
의학</label>
</li>
</div>
</form>
</div>
</ul>
</div>
<div class="panel-footer">
<button class="btn btn-primary" id="ramdomChatFindBtn" onclick="gethobby()">시작!</button>
<button class="btn btn-danger" id="exit">나가기</button>
</div>
</div>
</div>
</div>
</body>
</html>