summaryrefslogtreecommitdiffstats
path: root/quotepong.tcl
blob: 85d21418294fd6a55763be22dedf0751bc48ae92 (plain)
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
# quotepong.tcl by [sL] (Feb 14, 08)
# Based on quotepass.tcl by simple, guppy, [sL]
#
# Ascii Letter definitions provided by Freeder
#
# Description:
#
# Some EFnet servers require the user to type /quote pong :<cookie>
# when ident is broken or disabled.  This will send pong :<cookie> to
# the server when connecting.
#

set a2t_alphabet(a) "\n\     /\\    \n\
\   /  \\   \n\
\  / /\\ \\  \n\
\ / ____ \\ \n\
/_/    \\_\\\n"

set a2t_alphabet(b) "\  ____  \n\
|  _ \\ \n\
| |_) |\n\
|  _ < \n\
| |_) |\n\
|____/"

set a2t_alphabet(c) "\   _____ \n\
\ / ____|\n\
| |     \n\
| |     \n\
| |____ \n\
\ \\_____|"

set a2t_alphabet(d) "\  _____  \n\
|  __ \\ \n\
| |  | |\n\
| |  | |\n\
| |__| |\n\
|_____/ "

set a2t_alphabet(e) "\  ______ \n\
|  ____|\n\
| |__   \n\
|  __|  \n\
| |____ \n\
|______|\n"

set a2t_alphabet(f) "\  ______ \n\
|  ____|\n\
| |__   \n\
|  __|  \n\
| |     \n\
|_|     "


set a2t_alphabet(g) "\   _____\n\
\ / ____|\n\
| |  __ \n\
| | |_ |\n\
| |__| |\n\
\ \\_____|"

set a2t_alphabet(h) "\  _    _ \n\
| |  | |\n\
| |__| |\n\
|  __  |\n\
| |  | |\n\
|_|  |_|"

set a2t_alphabet(i) "\  _____ \n\
|_   _|\n\
\  | |  \n\
\  | |  \n\
\ _| |_ \n\
|_____|"

set a2t_alphabet(j) "\       _ \n\
\     | |\n\
\     | |\n\
\ _   | |\n\
| |__| |\n\
\ \\____/ "

set a2t_alphabet(k) "\  _  __\n\
| |/ /\n\
| ' / \n\
|  <  \n\
| . \\ \n\
|_|\\_\\"

set a2t_alphabet(l) "\  _      \n\
| |     \n\
| |     \n\
| |     \n\
| |____ \n\
|______|"

set a2t_alphabet(m) "\  __  __ \n\
|  \\/  |\n\
| \\  / |\n\
| |\\/| |\n\
| |  | |\n\
|_|  |_|"

set a2t_alphabet(n) "\  _   _ \n\
| \\ | |\n\
|  \\| |\n\
| . ` |\n\
| |\\  |\n\
|_| \\_|"


set a2t_alphabet(o) "\   ____  \n\
\ / __ \\ \n\
| |  | |\n\
| |  | |\n\
| |__| |\n\
\ \\____/ "

set a2t_alphabet(p) "\  _____  \n\
|  __ \\ \n\
| |__) |\n\
|  ___/ \n\
| |     \n\
|_|     "

set a2t_alphabet(q) "\   ____  \n\
\ / __ \\ \n\
| |  | |\n\
| |  | |\n\
| |__| |\n\
\ \\___\\_\\"

set a2t_alphabet(r) "\  _____  \n\
|  __ \\ \n\
| |__) |\n\
|  _  / \n\
| | \\ \\ \n\
|_|  \\_\\"

set a2t_alphabet(s) "\   _____ \n\
\ / ____|\n\
| (___  \n\
\ \\___ \\ \n\
\ ____) |\n\
|_____/ "

set a2t_alphabet(t) "\  _______ \n\
|__   __|\n\
\   | |   \n\
\   | |   \n\
\   | |   \n\
\   |_|   "


set a2t_alphabet(u) "\  _    _ \n\
| |  | |\n\
| |  | |\n\
| |  | |\n\
| |__| |\n\
\ \\____/ "

      
set a2t_alphabet(v) " __      __\n\
\\ \\    / /\n\
\ \\ \\  / / \n\
\  \\ \\/ /  \n\
\   \\  /   \n\
\    \\/    "

set a2t_alphabet(w) " __          __\n\
\\ \\        / /\n\
\ \\ \\  /\\  / / \n\
\  \\ \\/  \\/ /  \n\
\   \\  /\\  /   \n\
\    \\/  \\/    "


set a2t_alphabet(x) " __   __\n\
\\ \\ / /\n\
\ \\ V / \n\
\  > <  \n\
\ / . \\ \n\
/_/ \\_\\"

set a2t_alphabet(y) " __     __\n\
\\ \\   / /\n\
\ \\ \\_/ / \n\
\  \\   /  \n\
\   | |   \n\
\   |_|   "


set a2t_alphabet(z) "\  ______\n\
|___  /\n\
\   / / \n\
\  / /  \n\
\ / /__ \n\
/_____|"

proc a2t_ascii2text {ascii {count 6}} {
  global a2t_alphabet
#  foreach line [split $ascii \n] { putlog $line }
  set a2t_result ""
  for {set i 0} {$i < $count} {incr i} {
    foreach let [split abcdefghijklmnopqrstuvwxyz ""] {
      set match 1
      set tascii $ascii
      foreach alph_line [split $a2t_alphabet($let) \n] {
        set alph_line [string range $alph_line 1 end]
        set asc_line [lindex [split $tascii \n] 0]
        set tascii [join [lrange [split $tascii \n] 1 end] \n]
        # need to fix our match pattern
        regsub -all {\\} $alph_line {\\\\} alph_line
        if {![string match "[string trim $alph_line]*" [string trim $asc_line]]} {
          set match 0
          break
        }
      }
      if {$match} { 
        append a2t_result $let
        # remove the ascii letter
        set new_ascii [list]
        foreach alph_line [split $a2t_alphabet($let) \n] {
          set alph_line [string range $alph_line 1 end]
          set asc_line [lindex [split $ascii \n] 0]
          set ascii [join [lrange [split $ascii \n] 1 end] \n]
          # need to fix our regspec
          regsub -all {\\} $alph_line {\\\\} alph_line
          regsub -all {\|} $alph_line "\\|" alph_line
          regsub -all {\)} $alph_line "\\)" alph_line
          regsub -all {\(} $alph_line "\\(" alph_line

          regsub -- $alph_line "$asc_line" "" asc_line
          lappend new_ascii $asc_line
        }
        set ascii [join $new_ascii \n]
      }
      if {$match} { break }
    }
  }
  return [string toupper $a2t_result]
}

set quotepong_match "/QUOTE PONG :cookie"

bind evnt - init-server quotepong_unbind
bind evnt - disconnect-server quotepong_unbind
bind evnt - connect-server quotepong_bind

proc quotepong_servermsg {from cmd text} {
  global quotepong_match quotepong_count quotepong_ascii
  if {![info exists quotepong_count] && [string match "*$quotepong_match*" $text]} {
    set quotepong_count 0
    set quotepong_ascii [list]
    return 0
  }
  if {[info exists quotepong_count] && ($cmd == "998")} {
    if {$quotepong_count == 0} {
      putlog "Received ASCII Cookie from server:"
    }
    incr quotepong_count
    lappend quotepong_ascii [lindex [split $text :] 1]
    putlog "[lindex [split $text :] 1]"
    if {$quotepong_count == 6} {
      # time to send back to server
      set cookie [a2t_ascii2text [join $quotepong_ascii \n]]
      putlog "Sending Cookie to server: $cookie"
      putserv "PONG :$cookie"
      catch {unset quotepong_count}
    }
  }
  return 0
}

proc quotepong_unbind {type} {
  # Try to unbind our raw NOTICE bind once we are connected since it will
  # never be needed again
  catch {
    unbind raw - NOTICE quotepong_servermsg
    unbind raw - 998 quotepong_servermsg
  }
}

proc quotepong_bind {type} {
  bind raw - NOTICE quotepong_servermsg
  bind raw - 998 quotepong_servermsg
}