Class: All_user

Inherits:
Object
  • Object
show all
Defined in:
lib/irc_user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAll_user


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/irc_user.rb', line 14

def initialize
  @pos_write = 0
  @index=Hash.new # name => pos
  @name=Array.new # index => name
  @ip=Array.new
  @addr=Hash.new
  #@count_said=Array.new
  @sex=Array.new

  #[1]=>重复次数,[2]=>人品值
  #@RP=Array.new(3,[]) #why wrong , very surprised
  init_pp
  puts 'users class start' if $debug
end

Instance Attribute Details

#addrObject

Returns the value of attribute addr


12
13
14
# File 'lib/irc_user.rb', line 12

def addr
  @addr
end

#indexObject

Returns the value of attribute index


12
13
14
# File 'lib/irc_user.rb', line 12

def index
  @index
end

#RPObject

Returns the value of attribute RP


12
13
14
# File 'lib/irc_user.rb', line 12

def RP
  @RP
end

Instance Method Details

#add(nick, name, ip) ⇒ Object

记录nick库


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
# File 'lib/irc_user.rb', line 61

def add(nick,name,ip)
  nick.strip!
  name.gsub!(/[in]=|~|^\+|^\@/i,'') #删除nick 开头的@ + V
  ip=ip_from_webname(name) if ip =~ /^gateway\/web\/freenode/i
  index = @index[nick]
  print "index: #{index}  \t"
  if index
    if ip != @ip[index]
      chg_ip(nick,ip)
    end
    return false
  end
  puts " add nick: #{nick} "
  oldname = @index.key(@pos_write)
  #删除原位置
  @index.delete oldname
  @addr.delete oldname

  @addr[nick]= getaddr_fromip(ip)

  @index[nick] = @pos_write
  @name[@pos_write]= name
  @ip[@pos_write]= ip
  #@count_said[@pos_write] = @count_said[@pos_write].to_i + 1
  #puts @addr[nick]
  t = Time.now
  $time_in[@pos_write]= t
  $timelastsay[@pos_write]= t
  $timelastsayme[@pos_write]= t - 11
  $timelast6me[@pos_write]= $initFlood * 1.2
  $timelast6say[@pos_write]= $initFlood * 1.2
  $tWarned[@pos_write]= t - 3600#加入黑名单1个小时
  $lastsay[@pos_write]=nil
  #$ban_time=read_from_db
  $ban_time[@pos_write]=Time.now - 7200
  setmode(@pos_write,'')
  @RP[1][@pos_write] = 0
  setrp(@pos_write,ip)

  if @pos_write >= $maxNamed
    @pos_write = 0
    puts t.to_s.blueb
    puts @index.size
  else
    @pos_write += 1
  end
  @pos_write
end

#addrgrep(s) ⇒ Object


290
291
292
293
# File 'lib/irc_user.rb', line 290

def addrgrep(s)
  tmp = @addr.select{|x,y| y =~ /#{s.strip}/i}.to_a.map{|x,y| x}.sort
  return "#{tmp.count}#{tmp.join(' ')}"
end

#all_nickObject


277
278
279
# File 'lib/irc_user.rb', line 277

def all_nick
  @index.keys.map{|x| x.delete '@'}
end

#check_flood(nick) ⇒ Object


174
175
176
177
178
179
180
181
182
183
184
# File 'lib/irc_user.rb', line 174

def check_flood(nick)
  index = @index[nick]
  return unless index
  if ! $timelast6say[index]
    $timelast6say[index] = $initFlood 
  elsif $timelast6say[index] < 0
    $timelast6say[index] = $initFlood 
  end
  p "~ #{$timelast6say[index]}" if $timelast6say[index] < $maxflood + 6
  return $timelast6say[index] < $maxflood
end

#check_flood_me(nick) ⇒ Object

更严格


166
167
168
169
170
171
172
# File 'lib/irc_user.rb', line 166

def check_flood_me(nick)#更严格
  index = @index[nick]
  return unless index
  $timelast6me[index] = $initFlood * 2 if ! $timelast6me[index]
  p "~me #{$timelast6me[index]}" if $timelast6me[index] < $maxflood+10
  return $timelast6me[index] < $maxfloodme
end

#chg_ip(nick, ip) ⇒ Object


246
247
248
249
250
251
252
253
254
255
256
# File 'lib/irc_user.rb', line 246

def chg_ip(nick,ip)
  index = @index[nick]
  if index == nil #未记录的用户名
    return 1
  end

  @ip[index]=ip

  @addr[nick]= getaddr_fromip(ip)
  setrp(index,ip)
end

#chg_nick(old, new) ⇒ Object


258
259
260
261
262
263
264
265
266
267
# File 'lib/irc_user.rb', line 258

def chg_nick(old,new)
  index = @index[old]
  if index == nil #未记录的用户名
    return 1
  end
  @index[new]=index
  @index.delete(old)
  @addr[new]=@addr[old]
  @addr.delete(old)
end

#completename(s) ⇒ Object


281
282
283
284
285
# File 'lib/irc_user.rb', line 281

def completename(s)
  return s if !s or s=='' or @index.include?(s)
  #return @index.select{|x,y| x =~ /#{Regexp::escape s}/i}.keys[0]
  all_nick.grep(/#{s}/i)[0]
end

#del(nick, ip) ⇒ Object


268
269
270
271
272
273
# File 'lib/irc_user.rb', line 268

def del(nick,ip)
  return #if ip != '59.36.101.19'
  #return floodreset(nick)
  #index = @index[nick]
  #@index.delete(nick)
end

#floodmereset(nick) ⇒ Object


161
162
163
164
165
# File 'lib/irc_user.rb', line 161

def floodmereset(nick)
  index = @index[nick]
  return unless index
  $timelast6me[index] = $initFlood
end

#floodreset(nick) ⇒ Object


156
157
158
159
160
# File 'lib/irc_user.rb', line 156

def floodreset(nick)
  index = @index[nick]
  return unless index
  $timelast6say[index] = $initFlood
end

#get_ban_time(nick) ⇒ Object


123
124
125
# File 'lib/irc_user.rb', line 123

def get_ban_time(nick)
  $ban_time[@index[nick]] ||= Time.now - 3600
end

#getaddr(nick) ⇒ Object

记忆的IP


310
311
312
# File 'lib/irc_user.rb', line 310

def getaddr(nick)#记忆的IP
  return @addr[nick].to_s
end

#getip(nick) ⇒ Object

记忆的IP


305
306
307
308
309
# File 'lib/irc_user.rb', line 305

def getip(nick)#记忆的IP
  index = @index[nick]
  return unless index
  return @ip[index].to_s
end

#getLastSay(nick) ⇒ Object


152
153
154
# File 'lib/irc_user.rb', line 152

def getLastSay(nick)
  $lastsay[@index[nick]]
end

#getname(nick) ⇒ Object

return floodreset(nick) index = @index @index.delete(nick)


274
275
276
# File 'lib/irc_user.rb', line 274

def getname(nick)
  return @name[@index[nick]]
end

#getrp(nick) ⇒ Object

get 人品


53
54
55
56
57
58
# File 'lib/irc_user.rb', line 53

def getrp(nick)
  index = @index[nick]
  return 0 unless index
  @RP[2][index]=0 if not @RP[2][index]
  return @RP[2][index]
end

#has_said?(s) ⇒ Boolean


137
138
139
140
# File 'lib/irc_user.rb', line 137

def has_said?(s)
  return false if s.size < 4
  #true == $lastsay.compact.select{|x| break true if x =~ /#{s}/ }
end

#havenick?(nick) ⇒ Boolean


41
42
43
# File 'lib/irc_user.rb', line 41

def havenick?(nick)
  @index.include?(nick)
end

#ims(nick) ⇒ Object


313
314
315
# File 'lib/irc_user.rb', line 313

def ims(nick)
  "人品值:#{getrp nick}"
end

#init_ppObject


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/irc_user.rb', line 28

def init_pp
@RP=Array.new(3) {[]}
  $mode=Array.new
  $ban_time=Array.new
  $time_in=Array.new
  $timelastsay=Array.new
  $timelastsayme=Array.new
  $timelast6say=Array.new
  $timelast6me=Array.new
  $tWarned=Array.new
  $lastsay=Array.new
end

#ip_from_webname(name) ⇒ Object

解析网页登录的IP


46
47
48
49
50
# File 'lib/irc_user.rb', line 46

def ip_from_webname(name)
  #p ' ip_from_webname '
  #p name
  name.scan(/../).map{|x| x.hex}.join('.')
end

#ipgrep(ip) ⇒ Object


287
288
# File 'lib/irc_user.rb', line 287

def ipgrep(ip)
end

#isBlocked?(nick) ⇒ Boolean


110
111
112
113
114
115
# File 'lib/irc_user.rb', line 110

def isBlocked?(nick)
  index = @index[nick]
  return unless index
  $timelastsayme[index] = Time.now - 20 if ! $timelastsayme[index]
  return Time.now - $timelastsayme[index] < 5 #10秒之内就Block
end

#rep(nick) ⇒ Object

rep?


143
144
145
146
147
148
149
150
# File 'lib/irc_user.rb', line 143

def rep(nick)
  i=@index[nick]
  if @RP[1][i] > 2
    #print nick , ' 重复 rep . ' , @RP[1][i] , getLastSay(nick), 10.chr
    @RP[1][i]=0
    return true
  end
end

#said(nick, name, ip, fix = 0.0) ⇒ Object


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/irc_user.rb', line 205

def said(nick,name,ip,fix=0.0)
  if not @index
    puts '#无任何用户'
    return add(nick,name,ip)
  end
  if @index.include?(nick)
    index = @index[nick]
  else
    puts '#无此用户'
    return add(nick,name,ip)
  end
  #~ puts '21 $timelast6say[index]:  index: ' + index.to_s
  t = Time.now
  $timelastsay[index] = t if ! $timelastsay[index]
  $timelast6say[index] = $initFlood if ! $timelast6say[index]
  $timelast6say[index] = $initFlood if $timelast6say[index] > $initFlood or $timelast6say[index] < 1
  $timelast6say[index] = $timelast6say[index] / 5 * 4 + 
    (t - $timelastsay[index]) + fix + getrp(nick)/11.0
  $timelastsay[index] = t
end

#said_me(nick, name, ip, fix = 0.0) ⇒ Object


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/irc_user.rb', line 186

def said_me(nick,name,ip,fix=0.0)
  if ! @index
    return add(nick,name,ip)
  end
  if @index.include?(nick)
    index = @index[nick]
  else
    return add(nick,name,ip)
  end
  t = Time.now
  $timelastsayme[index] = t if ! $timelastsayme[index]
  $timelast6me[index] = $initFlood if ! $timelast6me[index]
  $timelast6me[index] = $initFlood if $timelast6me[index] > $initFlood or $timelast6me[index] < 1
  $timelast6me[index] = $timelast6me[index] / 5 * 4 + 
    (t-$timelastsayme[index]) + fix + getrp(nick)/12.0
  #p "~me #{nick} #{$timelast6me[index]}"
  $timelastsayme[index] = t
end

#saidAndCheckFlood(nick, name, ip, w) ⇒ Object


226
227
228
229
230
# File 'lib/irc_user.rb', line 226

def saidAndCheckFlood(nick,name,ip,w)
  said(nick,name,ip)
  setLastSay(nick,w)
  return check_flood(nick)
end

#saidAndCheckFloodMe(nick, name, ip) ⇒ Object


231
232
233
234
# File 'lib/irc_user.rb', line 231

def saidAndCheckFloodMe(nick,name,ip)
  said_me(nick,name,ip)
  return check_flood_me(nick)
end

#sayorderObject


117
118
# File 'lib/irc_user.rb', line 117

def sayorder()
end

#set_ban_time(nick) ⇒ Object


120
121
122
# File 'lib/irc_user.rb', line 120

def set_ban_time(nick)
  $ban_time[@index[nick]] = Time.now
end

#setip(nick, name, ip) ⇒ Object


294
295
296
297
298
299
# File 'lib/irc_user.rb', line 294

def setip(nick,name,ip)
  index = @index[nick]
  return add(nick,name,ip) unless index
  @ip[index]=ip
  @addr[nick]=getaddr_fromip(ip)
end

#setLastSay(nick, w) ⇒ Object


126
127
128
129
130
131
132
133
134
135
# File 'lib/irc_user.rb', line 126

def setLastSay(nick,w)
  i=@index[nick]
  i ||= add(nick)
  if w == $lastsay[i]
    @RP[1][i] +=1
  else
    @RP[1][i] =0
    $lastsay[i] =w
  end
end

#setmode(index, mode = '') ⇒ Object


301
302
303
# File 'lib/irc_user.rb', line 301

def setmode(index,mode='')
  $mode[index]=mode
end

#setrp(index, ip) ⇒ Object

用于flood检测等功能,可以有 10%的正加成


237
238
239
240
241
242
243
244
# File 'lib/irc_user.rb', line 237

def setrp(index,ip)
  if ip.match(/\w+\/\w+|unaffiliated/)
    p 'RP=30'
    @RP[2][index] = 40
  else
    @RP[2][index] = 0
  end
end