-
Notifications
You must be signed in to change notification settings - Fork 2
/
router.dm
169 lines (156 loc) · 5.05 KB
/
router.dm
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
/obj/machinery/router
networking = 1
icon = 'computer.dmi'
icon_state = "console"
name = "router"
density = 1
anchored = 1
security = 2
var/global/first_free_address_range = 1
/obj/machinery/router/var/address_range
/obj/machinery/router/var/list/connected[255]
/obj/machinery/router/var/mob/console_user
/obj/machinery/router/var/datum/os/OS
/obj/machinery/router/New()
var/area/A = src.loc.loc
src.name = "[A.name] Router"
address_range = first_free_address_range
address = address_range << 8
address |= 1
first_free_address_range += 1
// processing_items.Add(src) // Do this
OS = new(src)
// find things that aren't connected currently
for(var/obj/machinery/M in orange(15,src)) if(M.networking && !M.address)
connect(M)
..()
/obj/machinery/router/Del()
for(var/obj/machinery/M in connected)
disconnect(M)
..()
/obj/machinery/router/process()
if(console_user)
if(!(console_user in range(1,src)) || winget(console_user, "console", "is-visible") == "false")
console_user.hide_console()
if(OS)
for(var/mob/A in OS.mob_users)
if(!A)
OS.mob_users -= A
continue
if(!(A in range(1,src)) || winget(A.client, "console", "is-visible") == "false")
A.hide_console()
/obj/machinery/router/proc/connect(var/obj/machinery/M)
if(M.address) return
var/i = 1
NewIP:
i+=1
if(i > 100)
M.address = 0
return
// shift the address range to the left by 3 bytes
M.address = address_range << 8
M.address |= rand(2, 255)
if(connected[M.address % 256]) goto NewIP
connected[M.address % 256] = M
/obj/machinery/router/proc/disconnect(var/obj/machinery/M)
if(!M.address) return
connected[M.address % 256] = null
M.address = 0
/obj/machinery/router/call_function(var/datum/function/F)
if(uppertext(F.arg1) == net_pass)
//world << "AUTHED"
if(F.name == "who")
var/tp = /obj
if(F.arg1 == "apc")
tp = /obj/machinery/power/apc
else if(F.arg1 == "airlock")
tp = /obj/machinery/door/airlock
else if(F.arg1 == "status_display")
tp = /obj/machinery/status_display
else if(F.arg1 == "alarm")
tp = /obj/machinery/alarm
else if(F.arg1 == "router")
tp = /obj/machinery/router
else if(F.arg1 == "disposal")
tp = /obj/machinery/disposal
var/datum/function/R = new()
R.name = "response"
R.arg1 = ""
var/list/passes = list()
for(var/obj/M in connected) if(istype(M,tp))
if(istype(M,/obj/item/laptop))
if(M:OS:name != "ThinkThank")
R.arg1 += "[ip2text(M:address)]\t[M:OS:name]\n"
else
R.arg1 += "[ip2text(M:address)]\t[M.name]\n"
if(istype(M,/obj/machinery/))
var/area/A = get_area(M.loc)
if(M:security == 1 && !passes[A.name])
passes[A.name] = M:net_pass
else if(M:security == 2)
R.arg1 += "[ip2text(M:address)]\t[M.name][M:net_tag ? "([M:net_tag])" : ""]\[[M:net_pass]]\n"
else
R.arg1 += "[ip2text(M:address)]\t[M.name][M:net_tag ? "([M:net_tag])" : ""]\n"
for(var/obj/machinery/router/Ro in world) if(istype(Ro,tp))
R.arg1 += "[ip2text(Ro.address)]\tRouter\n"
R.arg1 += "Area Passwords\n"
for(var/A in passes)
var/pass = passes[A]
R.arg1 += "[A]:[pass]\n"
R.source_id = address
R.destination_id = F.source_id
receive_packet(src, R)
if(F.name == "response")
OS.receive_message(F.arg1)
else if(F.name == "who")
var/tp = /obj
if(F.arg1 == "apc")
tp = /obj/machinery/power/apc
else if(F.arg1 == "airlock")
tp = /obj/machinery/door/airlock
else if(F.arg1 == "status_display")
tp = /obj/machinery/status_display
else if(F.arg1 == "alarm")
tp = /obj/machinery/alarm
else if(F.arg1 == "router")
tp = /obj/machinery/router
else if(F.arg1 == "disposal")
tp = /obj/machinery/disposal
var/datum/function/R = new()
R.name = "response"
R.arg1 = ""
for(var/obj/M in connected) if(istype(M,tp))
if(istype(M,/obj/item/laptop))
if(M:OS:name != "ThinkThank")
R.arg1 += "[ip2text(M:address)]\t[M:OS:name]\n"
else
R.arg1 += "[ip2text(M:address)]\t[M.name]\n"
else if(M:net_tag)
R.arg1 += "[ip2text(M:address)]\t[M.name]([M:net_tag])\n"
else
R.arg1 += "[ip2text(M:address)]\t[M.name]\n"
for(var/obj/machinery/router/Ro in world) if(istype(Ro,tp))
R.arg1 += "[ip2text(Ro.address)]\tRouter\n"
R.source_id = address
R.destination_id = F.source_id
receive_packet(src, R)
if(F.name == "response")
OS.receive_message(F.arg1)
/obj/machinery/router/receive_packet(var/obj/machinery/sender, var/datum/function/P)
if(P.destination_id == src.address)
call_function(P)
return
// shift 3 bytes to the right to get the address range
var/router = P.destination_id >> 8
// if the destination is connected to this router, send to the destination
if(router == src.address_range)
for(var/obj/M in connected) if(M:address == P.destination_id)
M:receive_packet(src, P)
// otherwise, send to the router connected to the destination
else
for(var/obj/machinery/router/R in world) if(R.address_range == router)
R.receive_packet(src, P)
/obj/machinery/computer/console/attack_ai(var/mob/user as mob)
return src.attack_hand(user)
obj/machinery/router/attack_hand(mob/user as mob)
user.display_console(src)