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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
!
-
|
|
|
|
!
-
|
|
-
|
-
|
!
|
|
|
|
|
|
-
|
!
-
|
|
|
|
|
|
!
-
|
|
-
|
!
-
|
!
-
|
-
|
!
-
|
|
!
-
|
|
-
|
|
|
|
|
!
-
|
!
-
|
!
-
|
|
|
-
|
|
|
!
-
|
|
|
-
|
|
|
!
-
|
|
|
!
-
|
|
|
|
!
-
|
|
|
|
|
|
!
-
|
|
|
|
!
-
|
|
!
-
|
|
|
|
-
|
|
|
|
|
-
|
-
|
|
|
-
|
|
|
-
|
|
|
!
-
|
!
-
-
|
|
|
!
!
-
-
|
|
|
!
!
-
|
|
!
-
|
|
|
|
|
|
|
|
!
-
|
|
!
| #ifndef WM_TIMER
#define WM_TIMER $00000113
#endif
#module
#deffunc SJIS_To_JIS var buff2,var buff
sdim buff2,len*4
repeat
high=peek(buff,count)
if (high>0x7E&&high<0xA1)||(high>0xDE){
if tw=0:tw=1:lpoke buff2,count+count2,0x0042241b:count2+=3
low=peek(buff,count+1)
if high>=0xE0:high-=0x40
high<<=1
if low>=0x80&&low<=0x9E:low-
if low>=0x9F:low-=0x5F:high+
low-=0x1F:high-=0xE1
poke buff2,count+count2,high
poke buff2,count+1+count2,low
count+
}else{
if tw:tw=0:lpoke buff2,count+count2,0x0042281b:count2+=3
poke buff2,count+count2,high
}
count+
if count>=len{
if tw:tw=0:lpoke buff2,count+count2,0x0042281b:count2+=3
count=0
count2=0
break
}
loop
return
#deffunc JIS_To_SJIS var buff3,var buff4
len=strlen(buff4)
if len<=4:buff3=buff4:return
sdim buff3,len
repeat
high=peek(buff4,count+count2)
data=lpeek(buff4,count+count2)
data=data and 0x00ffffff
if data=0x0042241b:count2+=3:zen=1
if data=0x0042281b:count2+=3:zen=0
high=peek(buff4,count+count2)
if zen{
low=peek(buff4,count+count2+1)
if high&&0x01{
if low>=0x60:low+
}else{
low+=0x5F
}
if high>=0x5e:high+=0x80
high+=0xE1:high>>=1:low+=0x1F
poke buff3,count,high
poke buff3,count+1,low
count+
}else{
poke buff3,count,high
}
count+
if count>=len{
poke buff3,count-1,0
count=0
count2=0
zen=0
break
}
loop
return
#global
#module
#deffunc ircc_strcut array p1, str p2,str p3, local s1, local s2, local s3, local s4, local s5
s1=p2 s4=p3 sdim p1
repeat
s2=instr(s1,s3,p3)
if s2=-1{
s3=strlen(s1)+1
}else{
s3+=s2 }
p1(cnt)=strmid(s1,s5,s3-s5)
s3+=strlen(s4)
s5=s3
if s2=-1{
break
}
loop
return
#deffunc ircc_strcat var _var, array _array, str _str, local s1
sdim s1,64
repeat length(_array)-1
s1+=_array(cnt)+_str
loop
s1+=_array(length(_array)-1)
_var=s1
return
#global
#module ircc m_sockid, m_server, m_port, m_pass, m_nick, m_user, m_log, m_logsellen, m_timerid, m_timerflag, m_debugscreenid, m_new_privmsg, m_new_notice, m_new_channel_privmsg, m_new_channel_notice, m_connect, m_one
#include "pcbnet.as"
#uselib "user32.dll"
#func SetTimer "SetTimer" sptr,sptr,sptr,sptr
#func KillTimer "KillTimer" sptr,sptr
#modinit int _sockid, str _server, int _port, str _pass, str _nickname, str _username , str _hostname, str _servername, str _realname, int _timerid, local s1
m_sockid = _sockid
m_server = _server
m_port = _port
m_pass = _pass
m_nickname = _nickname
m_username = _username
m_hostname = _hostname
m_servername = _servername
m_realname = _realname
m_logsellen = 30 if _timerid=0{
m_timerid=1
}else{
m_timerid=_timerid
}
sdim m_log, 64
sdim m_new_channel_privmsg,64
sdim m_new_channel_notice,64
sdim m_new_privmsg,64
sdim m_new_notice,64
#ifdef _debug
s1=ginfo_sel
m_debugscreenid = 63-dcount dcount++
screen m_debugscreenid, 640,480
mesbox m_log,ginfo_winx,ginfo_winy
gsel s1
#endif
return
#modfunc mod_ircc_addlog str _str
m_log+=_str
notesel m_log
repeat notemax
if notemax>m_logsellen{
notedel
continue
}
loop
noteunsel
return
#ifdef _debug
#modfunc mod_ircc_logreflesh local _ginfo_sel
_ginfo_sel=ginfo_sel
gsel m_debugscreenid
objprm 0,m_log
gsel _ginfo_sel
return
#modfunc mod_ircc_debug_title str _title, local _ginfo_sel
_ginfo_sel=ginfo_sel
gsel m_debugscreenid
title _title
gsel _ginfo_sel
return
#endif
#modfunc ircc_duplog var _var
dup _var, m_log
return
#modfunc mod_ircc_connect local s1, local s2, local s3, local x1, local x2, local size, local connected
tcpopen m_sockid, m_server, m_port repeat 6000
tcpiscon m_sockid
if stat==1{
connected=1
break
}else:if stat==2{
mod_ircc_addlog thismod, "IRCC: tcpopen error.\n"
#ifdef _debug
mod_ircc_logreflesh thismod
#endif
break
}
wait 1
loop
if connected=1{
SetTimer hwnd, m_timerid, 500, 0
}
return connected
#modfunc mod_ircc_join str _channelname, local s1
if _channelname="":return
mod_ircc_addlog thismod, "JOIN "+_channelname+"\n"
ircc_strcut s1,_channelname,","
foreach s1
tcpput "JOIN "+s1(cnt)+"\n", m_sockid
loop
return
#modfunc mod_ircc_part str _channelname, str _partmessage, local s1, local s2
if _channelname="":return
if _partmessage!""{
s1=" :"+_partmessage
}
mod_ircc_addlog thismod, "PART "+_channelname+s1+"\n"
ircc_strcut s2,_channelname,","
foreach s2
tcpput "PART "+s2(cnt)+s1+"\n", m_sockid
loop
return
#modfunc mod_ircc_notice str _channelname, str _message, local s1
if _message="":return
if _channelname="":return
mod_ircc_addlog thismod, "NOTICE "+_channelname+" :"+_message+"\n"
ircc_strcut s1,_channelname,","
foreach s1
tcpput "NOTICE "+s1(cnt)+" :"+_message+"\n", m_sockid
loop
return
#modfunc mod_ircc_privmsg str _channelname, str _message, local s1
if _message="":return
if _channelname="":return
mod_ircc_addlog thismod, "privmsg "+_channelname+" :"+_message+"\n"
ircc_strcut s1,_channelname,","
foreach s1
tcpput "privmsg "+s1(cnt)+" :"+_message+"\n", m_sockid
loop
return
#modfunc mod_new_privmsg_add str _channelname, str _str
repeat
if length(m_new_privmsg)<=cnt{
m_new_channel_privmsg(cnt)=_channelname
m_new_privmsg(cnt)=_str
break
}else:if m_new_channel_privmsg(cnt)=""{
m_new_channel_privmsg(cnt)=_channelname
m_new_privmsg(cnt)=_str
break
}
loop
return
#modfunc mod_new_notice_add str _channelname, str _str
repeat
if length(m_new_notice)<=cnt{
m_new_channel_notice(cnt)=_channelname
m_new_notice(cnt)=_str
break
}else:if m_new_channel_notice(cnt)=""{
m_new_channel_notice(cnt)=_channelname
m_new_notice(cnt)=_str
break
}
loop
return
#modfunc mod_ircc_connect_infosend
if m_pass!""{
tcpput "PASS "+m_pass+"\n", m_sockid
mod_ircc_addlog thismod, "PASS "+m_pass+"\n"
if stat!0:mod_ircc_addlog thismod, "IRCC: PASSを送れませんでした\n"
}
tcpput "NICK "+m_nickname+"\n", m_sockid
mod_ircc_addlog thismod, "NICK "+m_nickname+"\n"
if stat!0:mod_ircc_addlog thismod, "IRCC: NICKを送れませんでした\n"
tcpput "USER "+m_username+" "+m_hostname+" "+m_servername+" :"+m_realname+"\n", m_sockid
mod_ircc_addlog thismod, "USER "+m_username+" "+m_hostname+" "+m_servername+" :"+m_realname+"\n"
if stat!0:mod_ircc_addlog thismod, "IRCC: USERを送れませんでした\n"
return
#modfunc mod_ircc_timer local get, local s1, local s2, local s3, local s4, local size, local x1, local x2, local x3, local flag
if m_connect=0{
mod_ircc_connect_infosend thismod
m_connect=1
}
tcpfail m_sockid
if stat==2{
#ifdef _debug
mod_ircc_addlog thismod, "IRCC :通信が切断されました\nIRCC: このモジュール変数はdelmodによって削除されます\nIRCC :mod_ircc_timerの戻り値に-1が返されました\n開発者はこの戻り値で再接続をするプログラムを書くことが出来ます\n"
mod_ircc_logreflesh thismod
#endif
delmod thismod
return -1
}
sdim x1,64
repeat 120
tcpcount s1, m_sockid
if s1>0 {
sdim s2, s1+1
tcpget s2, s1, m_sockid
x1+=s2
wait 0
}else:break
loop
notesel x1
repeat notemax
if ping=1:ping=0
noteget s3,cnt
if peek(s3)=10: getstr s3 ,s3, 1
ircc_strcut s3, s3, " "
if s3(0)="PING"{
tcpput "PONG "+m_nickname+"\n", m_sockid
ping=1
}
if length(s3)>=2:if s3(1)=="PRIVMSG"{
x2=strmid(s3(3), 1, strlen(s3(3)))
JIS_To_SJIS x3,x2
s3(3)=":"+x3
mod_new_privmsg_add thismod, s3(2),s3(3)
}else:if s3(1)=="NOTICE"{
x2=strmid(s3(3), 1, strlen(s3(3)))
JIS_To_SJIS x3,x2
s3(3)=":"+x3
mod_new_notice_add thismod, s3(2),s3(3)
}else:if s3(1)=="001"{
flag=1
}else:if s3(1)=="433"{
m_nickname+="_" mod_ircc_connect_infosend thismod
}else:if (s3(1)=="QUIT")|(s3(1)=="PART")|(s3(1)=="TOPIC"){
x2=strmid(s3(3), 1, strlen(s3(3)))
JIS_To_SJIS x3,x2
s3(3)=":"+x3
}else:if s3(1)=="332"{
x2=strmid(s3(4), 1, strlen(s3(4)))
JIS_To_SJIS x3,x2
s3(4)=":"+x3
}
ircc_strcat s3, s3, " "
mod_ircc_addlog thismod, s3+"\n"
if ping=1{
mod_ircc_addlog thismod, "PONG "+m_nickname+"\n"
}
#ifdef _debug
mod_ircc_logreflesh thismod #endif
loop
#ifdef _debug
mod_ircc_debug_title thismod, "TIMER:"+cc+" "
cc+
#endif
if m_timerflag=0: m_timerflag=1
return flag
#modfunc mod_ircc_instr_privmsg str _channelname, str _inmessage
foreach m_new_privmsg
if m_new_channel_privmsg(cnt)=_channelname{
if instr(m_new_privmsg(cnt), 0, _inmessage)!-1{
m_new_channel_privmsg(cnt)=""
m_new_privmsg(cnt)=""
return 1
}
}
loop
return 0
#modfunc mod_ircc_instr_notice str _channelname, str _inmessage
foreach m_new_notice
if m_new_channel_notice(cnt)=_channelname{
if instr(m_new_notice(cnt), 0, _inmessage)!-1{
m_new_channel_notice(cnt)=""
m_new_notice(cnt)=""
return 1
}
}
loop
return 0
#modterm
KillTimer hwnd, m_timerid
tcpshut m_sockid
tcpclose m_sockid
return
#global
#if 0
gsel 0
newmod irc,ircc, 0, "127.0.0.1", 6667, "", "TEST", "TEST", "TEST", "TEST", "TEST", 1
mod_ircc_connect irc
if stat==1{
title "connected"
oncmd gosub *IRCC_TIMER, WM_TIMER
}
stop
*IRCC_TIMER
mod_ircc_timer irc if stat{
mod_ircc_join irc, "#test,#test2,#test3,#test4,#test5"
mod_ircc_privmsg irc, "#test,#test2,#test3,#test4,#test5", "やあこんばんは"
mod_ircc_part irc, "#test3,#test4,#test5", "Bye"
}
mod_ircc_instr_privmsg irc, "#test", "時報"
if stat{
mod_ircc_notice irc,"#test","今"+gettime(4)+"時だぜ"
}
return
#endif
|