SHOW:
|
|
- or go back to the newest paste.
| 1 | --[[ | |
| 2 | ||
| 3 | Создано командой SOCC company | |
| 4 | Nightmare_Night | |
| 5 | ||
| 6 | P.S. Программа написана на скорую руку | |
| 7 | Просьба тапками не кидаться | |
| 8 | ||
| 9 | P.S.S. Функция получения времени хост-машины была взята из API ECS | |
| 10 | ||
| 11 | ]]-- | |
| 12 | ||
| 13 | local component = require("component")
| |
| 14 | local term = require("term")
| |
| 15 | local event = require("event")
| |
| 16 | local fs = require("filesystem")
| |
| 17 | ||
| 18 | local gpu = component.gpu | |
| 19 | ||
| 20 | local LOG_PATH = "chat_log.txt" | |
| 21 | ||
| 22 | -- Конвертирует строку в массив | |
| 23 | function stringToArray(text) | |
| 24 | t = {}
| |
| 25 | text:gsub(".",function(c) table.insert(t,c) end)
| |
| 26 | return t | |
| 27 | end | |
| 28 | ||
| 29 | --Получить текущее реальное время компьютера, хостящего сервер майна | |
| 30 | function getHostTime(timezone) | |
| 31 | timezone = timezone or 2 | |
| 32 | local file = io.open("/HostTime.tmp", "w")
| |
| 33 | file:write("")
| |
| 34 | file:close() | |
| 35 | local timeCorrection = timezone * 3600 | |
| 36 | local lastModified = tonumber(string.sub(fs.lastModified("/HostTime.tmp"), 1, -4)) + timeCorrection
| |
| 37 | fs.remove("/HostTime.tmp")
| |
| 38 | local year, month, day, hour, minute, second = os.date("%Y", lastModified), os.date("%m", lastModified), os.date("%d", lastModified), os.date("%H", lastModified), os.date("%M", lastModified), os.date("%S", lastModified)
| |
| 39 | return tonumber(day), tonumber(month), tonumber(year), tonumber(hour), tonumber(minute), tonumber(second) | |
| 40 | end | |
| 41 | ||
| 42 | -- Получет настоящее время, стоящее на Хост-машине | |
| 43 | function real_time() | |
| 44 | local time = {getHostTime(3)}
| |
| 45 | local text = string.format("%02d:%02d:%02d", time[4], time[5], time[6])
| |
| 46 | return text | |
| 47 | end | |
| 48 | ||
| 49 | -- Проверяет является ли текст окрашенным | |
| 50 | function isColored(text) | |
| 51 | for pos, i in pairs(stringToArray(text)) do | |
| 52 | if (i ~= "&") then | |
| 53 | if (i ~= " ") then | |
| 54 | return false | |
| 55 | end | |
| 56 | else | |
| 57 | return true | |
| 58 | end | |
| 59 | end | |
| 60 | ||
| 61 | return true | |
| 62 | end | |
| 63 | ||
| 64 | -- Проверяет в глобальном ли чате написано сообщение | |
| 65 | function isGlobal(text) | |
| 66 | for pos, i in pairs(stringToArray(text)) do | |
| 67 | if (i ~= "!") then | |
| 68 | if (i ~= " ") then | |
| 69 | return false | |
| 70 | end | |
| 71 | else | |
| 72 | return true, pos | |
| 73 | end | |
| 74 | end | |
| 75 | return false | |
| 76 | end | |
| 77 | ||
| 78 | -- Делит строку на части | |
| 79 | function split(str, pat) | |
| 80 | local t = {}
| |
| 81 | local fpat = "(.-)" .. pat | |
| 82 | local last_end = 1 | |
| 83 | local s, e, cap = str:find(fpat, 1) | |
| 84 | while s do | |
| 85 | if s ~= 1 or cap ~= "" then | |
| 86 | table.insert(t,cap) | |
| 87 | end | |
| 88 | last_end = e+1 | |
| 89 | s, e, cap = str:find(fpat, last_end) | |
| 90 | end | |
| 91 | if last_end <= #str then | |
| 92 | cap = str:sub(last_end) | |
| 93 | table.insert(t, cap) | |
| 94 | end | |
| 95 | return t | |
| 96 | end | |
| 97 | ||
| 98 | -- Устанавливает цвет шрифта в зависимости от патерна | |
| 99 | function setColor(num) | |
| 100 | if (num == "0") then | |
| 101 | gpu.setForeground(0x333333) | |
| 102 | end | |
| 103 | ||
| 104 | if (num == "1") then | |
| 105 | gpu.setForeground(0x000099) | |
| 106 | end | |
| 107 | ||
| 108 | if (num == "2") then | |
| 109 | gpu.setForeground(0x006600) | |
| 110 | end | |
| 111 | ||
| 112 | if (num == "3") then | |
| 113 | gpu.setForeground(0x006666) | |
| 114 | end | |
| 115 | ||
| 116 | if (num == "4") then | |
| 117 | gpu.setForeground(0x660000) | |
| 118 | end | |
| 119 | ||
| 120 | if (num == "5") then | |
| 121 | gpu.setForeground(0x660066) | |
| 122 | end | |
| 123 | ||
| 124 | if (num == "6") then | |
| 125 | gpu.setForeground(0xFF8000) | |
| 126 | end | |
| 127 | ||
| 128 | if (num == "7") then | |
| 129 | gpu.setForeground(0xA0A0A0) | |
| 130 | end | |
| 131 | ||
| 132 | if (num == "8") then | |
| 133 | gpu.setForeground(0x404040) | |
| 134 | end | |
| 135 | ||
| 136 | if (num == "9") then | |
| 137 | gpu.setForeground(0x3399FF) | |
| 138 | end | |
| 139 | ||
| 140 | if (num == "a") then | |
| 141 | gpu.setForeground(0x99FF33) | |
| 142 | end | |
| 143 | ||
| 144 | if (num == "b") then | |
| 145 | gpu.setForeground(0x00FFFF) | |
| 146 | end | |
| 147 | ||
| 148 | if (num == "c") then | |
| 149 | gpu.setForeground(0xFF3333) | |
| 150 | end | |
| 151 | ||
| 152 | if (num == "d") then | |
| 153 | gpu.setForeground(0xFF00FF) | |
| 154 | end | |
| 155 | ||
| 156 | if (num == "e") then | |
| 157 | gpu.setForeground(0xFFFF00) | |
| 158 | end | |
| 159 | ||
| 160 | if (num == "f") then | |
| 161 | gpu.setForeground(0xFFFFFF) | |
| 162 | end | |
| 163 | end | |
| 164 | ||
| 165 | -- Выводит сообщение | |
| 166 | function writeMessage(text) | |
| 167 | local t = split(text, "&") | |
| 168 | for pos, i in pairs(t) do | |
| 169 | if (pos == 1 and not isColored(text)) then | |
| 170 | io.write(i) | |
| 171 | else | |
| 172 | setColor(string.sub(i, 1, 1)) | |
| 173 | io.write(string.sub(i, 2)) | |
| 174 | end | |
| 175 | end | |
| 176 | end | |
| 177 | ||
| 178 | -- Выводит остальную часть сообщения | |
| 179 | function message(nick, msg, isGlobal, pos) | |
| 180 | local type = "" | |
| 181 | if (isGlobal) then msg = string.sub(msg, pos + 1) type = "G" else type = "L" end | |
| 182 | ||
| 183 | local file = fs.open(LOG_PATH, "a") | |
| 184 | file:write("[" .. real_time() .. "] [" .. type .. "] " .. nick .. ": " .. msg .. "\n")
| |
| 185 | file:close() | |
| 186 | ||
| 187 | gpu.setForeground(0x00FFFF) | |
| 188 | io.write("[" .. real_time() .. "] ")
| |
| 189 | gpu.setForeground(0xFFFFFF) | |
| 190 | if (type == "G") then | |
| 191 | gpu.setForeground(0xFF9933) | |
| 192 | else | |
| 193 | gpu.setForeground(0xFFFFFF) | |
| 194 | end | |
| 195 | io.write("[" .. type .. "] ")
| |
| 196 | gpu.setForeground(0x00FF00) | |
| 197 | io.write(nick) | |
| 198 | gpu.setForeground(0xFFFFFF) | |
| 199 | io.write(": ")
| |
| 200 | writeMessage(msg, l) | |
| 201 | io.write("\n")
| |
| 202 | end | |
| 203 | ||
| 204 | local c, fs = require("component"), require("filesystem")
| |
| 205 | local gpu = c.gpu | |
| 206 | - | local TC, RO, RN, RD, TPS = 0.3, 0, 0, 0 |
| 206 | + | local TC, RO, RN, RD, TPS = 1, 0, 0, 0 |
| 207 | ||
| 208 | local admins = {
| |
| 209 | {"max32","макс"},
| |
| 210 | {"OSSO","OSSO"},
| |
| 211 | {"Garou","Garou"},
| |
| 212 | {"__HAPKOMAH__","нарик"},
| |
| 213 | {"LiwMorgan","ливМорган"},
| |
| 214 | {"Alpaka_Masha","альпака"},
| |
| 215 | {"Turgor","тургор"}
| |
| 216 | ||
| 217 | ||
| 218 | ||
| 219 | } | |
| 220 | ||
| 221 | ||
| 222 | ||
| 223 | local component = require("component")
| |
| 224 | local computer = require("computer")
| |
| 225 | local unicode = require("unicode")
| |
| 226 | local event = require("event")
| |
| 227 | local gpu = component.gpu | |
| 228 | local w,h = gpu.getViewport() | |
| 229 | ||
| 230 | local function check() | |
| 231 | local line = 3 | |
| 232 | for ind = 1,#admins do | |
| 233 | local name = admins[ind][1] | |
| 234 | local rank = admins[ind][2] | |
| 235 | gpu.setForeground(0xFFFFFF) | |
| 236 | -- gpu.set(130,line,"[") | |
| 237 | -- gpu.set(unicode.len(rank)+2,line,"] - "..name) | |
| 238 | gpu.set(131,line,rank) | |
| 239 | if computer.addUser(name) then | |
| 240 | computer.removeUser(name) | |
| 241 | gpu.setForeground(0x00FF00) | |
| 242 | gpu.set(140,line,"online") | |
| 243 | else | |
| 244 | gpu.setForeground(0x999999) | |
| 245 | gpu.set(140,line,"offline") | |
| 246 | end | |
| 247 | line = line + 1 | |
| 248 | end | |
| 249 | end | |
| 250 | ||
| 251 | ||
| 252 | gpu.setForeground(0x99b2f2) | |
| 253 | gpu.set(1, 2, "TPS Сервера:") | |
| 254 | local function time() | |
| 255 | local f = io.open("/tmp/TF", "w")
| |
| 256 | f:write("test")
| |
| 257 | f:close() | |
| 258 | return(fs.lastModified("/tmp/TF"))
| |
| 259 | end | |
| 260 | ||
| 261 | - | print("Инициализация...")
|
| 261 | + | --print("Инициализация...")
|
| 262 | - | os.sleep(0.1) |
| 262 | + | --os.sleep(0.1) |
| 263 | - | print("Ожидание первого сообщения...")
|
| 263 | + | --print("Ожидание первого сообщения...")
|
| 264 | ||
| 265 | local _, add, nick, msg = event.pull("chat_message")
| |
| 266 | term.clear() | |
| 267 | local type, pos = isGlobal(msg) | |
| 268 | message(nick, msg, type, pos) | |
| 269 | ||
| 270 | ||
| 271 | --computer.addUser(({event.pull("touch")})[6])
| |
| 272 | ||
| 273 | while true do | |
| 274 | ||
| 275 | - | local _, add, nick, msg = event.pull("chat_message")
|
| 275 | + | |
| 276 | - | local type, pos = isGlobal(msg) |
| 276 | + | RO = time() |
| 277 | - | message(nick, msg, type, pos) |
| 277 | + | os.sleep(TC) |
| 278 | RN = time() | |
| 279 | RD = RN - RO | |
| 280 | TPS = 20000 * TC / RD | |
| 281 | TPS = string.sub(TPS, 1, 5) | |
| 282 | nTPS = tonumber(TPS) | |
| 283 | gpu.setForeground(0x00FF00) | |
| 284 | gpu.set(137, 2, " ") | |
| 285 | gpu.set(137, 2, " TPS - "..TPS) | |
| 286 | ||
| 287 | check() | |
| 288 | ||
| 289 | end |