#==============================================================================
# ■ Core
#------------------------------------------------------------------------------
# Core : 모듈 관리 클래스입니다.
#==============================================================================
class Core
def initialize
@Module = {}
@Module['Core'] = self
@temp_pdata = ""
@pdata = Array.new
self.executeQuery('Core:gameseting',nil)
self.executeQuery('TCPSocket:new',{'host'=>@host, 'port'=>@port})
end
def gameseting(obj)
########################################################################
@host = "127.0.0.1"
@port = 1005
@ver = "1.0.0"
@width = 800
@height = 600
########################################################################
Graphics.frame_rate = 60
self.executeQuery('Win32API:SetWindowPos',{'width'=>@width, 'height'=>@height})
end
def update
if self.executeQuery('TCPSocket:ready?',nil)
temp, plen = self.executeQuery('TCPSocket:recv',{'len'=>0xfff, 'flags'=>0})
@temp_pdata = @temp_pdata + temp[0...plen]
while 1
if @temp_pdata.size > 0 and @temp_pdata[0] < @temp_pdata.size
plen = ""
for i in 0...@temp_pdata[0].to_i
if @temp_pdata[i+1]==0
plen = plen + "00"
else
plen = plen + @temp_pdata[i+1].to_s
end
end
plen = plen.to_i
temp = @temp_pdata.size + 1
temp2 = @temp_pdata[0] + 1 + plen
if (plen+@temp_pdata[0].to_i+1) <= temp2
@pdata.push(@temp_pdata[0...temp2])
if temp >= (temp2+1)
@temp_pdata = @temp_pdata[temp2...temp]
else
break
end
end
else
break
end
end
end
for data in @pdata
########################전체 길이 제거#############################
d, temp = readdata(data)
query, d = readdata(d)
objnum = ""
for i in 0...d[0].to_i
if d[i+1]==0 then
objnum = objnum + "00"
else
objnum = objnum + d[i+1].to_s
end
end
i = i + 2
d = d[i...d.size]
objnum = objnum.to_i
obj = {}
for i in 0...objnum
name_type = d[0]
d = d[1...d.size]
name, d = readdata(d)
value_type = d[0]
d = d[1...d.size]
value, d = readdata(d)
if name_type == 2
name = name.to_i
end
if value_type == 2
value = value.to_i
end
obj[name] = value
end
###################################################################
@pdata.delete(data)
self.executeQuery(query,obj)
end
@Module.each {|mod|
if mod[1] != self
mod[1].update
end
}
end
def readdata(data)
plen = ""
for i in 0...data[0].to_i
if data[i+1]==0
plen = plen + "00"
else
plen = plen + data[i+1].to_s
end
end
i = i + 2
plen = plen.to_i
pdata = data[i...(plen+2)]
return pdata, data[(plen+2)...data.size]
end
def executeQuery(query, obj)
querydata = query.split(":")
if querydata[1] == "new"
return eval(sprintf("@Module['%s'] = %s.new(obj)",querydata[0],querydata[0]))
else
if @Module[querydata[0]]
return eval(sprintf("@Module['%s'].%s(obj)",querydata[0],querydata[1]))
else
return eval(sprintf("%s.%s(obj)",querydata[0],querydata[1]))
end
end
end
def SendQuery(query, obj)
data = ""
temp = nil
temp2 = nil
qdata = senddata(query)
temp = obj.size
objdata = lendata(temp)
for d in obj do
objdata = objdata + objtype(d[0]).to_i.chr
objdata = objdata + senddata(d[0].to_s)
objdata = objdata + objtype(d[1]).to_i.chr
objdata = objdata + senddata(d[1].to_s)
end
data = qdata + objdata
data = lendata(data.size) + data
@Module['TCPSocket'].send(data)
end
def senddata(data)
r = lendata(data.size)
r = r + data
return r
end
def objtype(objdata)
data = objdata.class
r = 0
if data == "String"
r = 1
elsif data == "Fixnum" or data == "Bignum" or data == "Float"
r = 2
end
return r
end
def lendata(strlen)
data = ""
temp = nil
temp2 = nil
temp = strlen.to_s.size
temp2 = (temp/2.0+0.5).to_i#math.floor
data = temp2.to_i.chr
for i in 1...(temp2+1) do
data = data + strlen.to_s[((i-1)*2)...((i-1)*2+2)].to_i.chr
end
return data
end
end
구경이나 하세요.
RKC에서 Rollellcoda이라는 분이 내가 백호이면 올려보라고 하길래 올려봄.
퍼가면 나쁜사람이에여~!