-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcap_helper.py
240 lines (183 loc) · 6.85 KB
/
pcap_helper.py
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
def get_landblock_entry(command):
landblock_entry = LandblockEntry(
get_guid(command),
get_wcid(command),
get_cell_id(command),
get_origin_xyz(command),
get_angles_wxyz(command),
get_last_modified(command),
get_name(command)
)
return landblock_entry
def get_links(filtered_list, parent_guid, wcid_set):
if len(wcid_set) == 0:
return None
entry = None
my_list = []
for entry in filtered_list:
if entry.wcid in wcid_set:
my_list.append(entry)
entry.is_link_child = True
for i in range(len(my_list)):
if i == 0:
entry = """INSERT INTO `landblock_instance_link` (`parent_GUID`, `child_GUID`, `last_Modified`)\n"""
entry += f"""VALUES ({parent_guid}, {my_list[i].guid}, '2019-02-10 00:00:00') /* {my_list[i].name} */"""
else:
entry += f"""\n , ({parent_guid}, {my_list[i].guid}, '2019-02-10 00:00:00') /* {my_list[i].name} */"""
entry += ";\n\n"
return entry
def filter_by_proximity(landblock_entries, proximity):
filtered_list = landblock_entries.copy()
to_remove = []
groups = {}
for entry in landblock_entries:
groups.setdefault(entry.wcid, []).append(entry)
nested_list = [groups[wcid] for wcid in sorted(groups.keys())]
for my_list in nested_list:
for i in my_list:
for j in my_list:
if i == j:
pass
else:
d = calc_distance(i, j)
if d < proximity:
if i in to_remove or j in to_remove:
pass
else:
to_remove.append(i)
for entry in to_remove:
filtered_list.remove(entry)
return filtered_list
def calc_distance(p1, p2):
"""Calculate the distance between 2 weenies."""
d = ((p2.ox - p1.ox) ** 2 + (p2.oy - p1.oy) ** 2 + (p2.oz - p1.oz) ** 2) ** 0.5
return d
def filter_by_range(landblock_entries, x_min, x_max, y_min, y_max, z_min, z_max):
filtered_list = []
for entry in landblock_entries:
if (x_max >= entry.ox >= x_min) and (y_max >= entry.oy >= y_min) and (z_max >= entry.oz >= z_min):
filtered_list.append(entry)
return filtered_list
def get_clean_list(filtered_list, ignore_wcids):
my_list = []
for entry in filtered_list:
if entry.wcid in ignore_wcids:
pass
else:
my_list.append(entry)
return my_list
def get_guid(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
parentheses_split = comma_split[0].split("(")
return parentheses_split[1].strip()
def get_wcid(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
return comma_split[1].strip()
def get_name(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
try:
asterisk_split = split_entry[1].split("*")
my_data = asterisk_split[1].strip()
except IndexError:
my_data = "Placeholder Name"
return my_data
def get_cell_id(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
return comma_split[2].strip()
def get_origin_xyz(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
x = float(comma_split[3].strip())
y = float(comma_split[4].strip())
z = float(comma_split[5].strip())
return x, y, z
def get_angles_wxyz(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
w = float(comma_split[6].strip())
x = float(comma_split[7].strip())
y = float(comma_split[8].strip())
z = float(comma_split[9].strip())
return w, x, y, z
def get_is_link_child(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
return comma_split[10].strip()
def get_last_modified(command):
split_entry = command.split("\n")
if "VALUES" in split_entry[1]:
comma_split = split_entry[1].split(",")
more_split = comma_split[11].split(")")
return more_split[0].strip()
class LandblockEntry:
def __init__(self, guid, wcid, cell, origin, angles, last_modified, name):
self.guid = guid
self.wcid = int(wcid)
self.cell = cell
self.ox = origin[0]
self.oy = origin[1]
self.oz = origin[2]
if self.ox == 0.0:
self.ox = 0
if self.oy == 0.0:
self.oy = 0
if self.oz == 0.0:
self.oz = 0
if self.ox == 1.0:
self.ox = 1
if self.oy == 1.0:
self.oy = 1
if self.oz == 1.0:
self.oz = 1
if self.ox == -1.0:
self.ox = -1
if self.oy == -1.0:
self.oy = -1
if self.oz == -1.0:
self.oz = -1
self.aw = angles[0]
self.ax = angles[1]
self.ay = angles[2]
self.az = angles[3]
if self.aw == 0.0:
self.aw = 0
if self.ax == 0.0:
self.ax = 0
if self.ay == 0.0:
self.ay = 0
if self.az == 0.0:
self.az = 0
if self.aw == 1.0:
self.aw = 1
if self.ax == 1.0:
self.ax = 1
if self.ay == 1.0:
self.ay = 1
if self.az == 1.0:
self.az = 1
if self.aw == -1.0:
self.aw = -1
if self.ax == -1.0:
self.ax = -1
if self.ay == -1.0:
self.ay = -1
if self.az == -1.0:
self.az = -1
self.is_link_child = False
self.last_modified = last_modified
self.name = name
def get_sql_entry(self):
entry = """INSERT INTO `landblock_instance` (`guid`, `weenie_Class_Id`, `obj_Cell_Id`, `origin_X`, `origin_Y`, `origin_Z`, `angles_W`, `angles_X`, `angles_Y`, `angles_Z`, `is_Link_Child`, `last_Modified`)\n"""
entry += f"""VALUES ({self.guid}, {self.wcid}, {self.cell}, {self.ox}, {self.oy}, {self.oz}, {self.aw}, {self.ax}, {self.ay}, {self.az}, {self.is_link_child}, {self.last_modified}); /* {self.name} */\n"""
entry += f"""/* @teleloc {self.cell} [{self.ox} {self.oy} {self.oz}] {self.aw} {self.ax} {self.ay} {self.az} */\n\n"""
return entry