-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenSeed.gd
1302 lines (1086 loc) · 36.8 KB
/
OpenSeed.gd
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
extends Node
# Setup variables
var thread = Thread.new()
var imgfile = File.new()
var Imagedata = Image.new()
var noimage = preload("res://OpenSeed-Godot/folder-music-symbolic.svg")
var username = ""
# warning-ignore:unused_class_variable
var passphrase = ""
# warning-ignore:unused_class_variable
var email = ""
var token = ""
var steem = ""
# warning-ignore:unused_class_variable
var postingkey = ""
# warning-ignore:unused_class_variable
var steem_node = ""
# warning-ignore:unused_class_variable
var devPub = ""
var devId = ""
# warning-ignore:unused_class_variable
var appPub = ""
var appId = ""
var openseed = "openseed.solutions"
var version = ""
var ipfs = ""
var connection = ""
# warning-ignore:unused_class_variable
var output = ""
var online = true
#var mode = "socket"
#var mode = "web"
var mode = "websocket"
var keys = []
var waiting = false
export var debug = true
#var threadedServer = StreamPeerTCP.new()
#var threadedServerInternal = StreamPeerTCP.new()
#Profile variables
var profile_name = "User"
var profile_email = "[email protected]"
var profile_about = "Does things and stuff"
var profile_phone = ""
var profile_image = ""
var profile_creator = false
var profile_owns = []
var profile_creator_Id = ""
var profile_creator_Pub = ""
var conversations = []
var chatlog = []
# Image store. This is used to access any images that come from OpenSeed itself
# We use a standard dictionary where the image name is the key and the texture is the value.
# We will have functions to set and retrieve image data.
var image_store = {}
var playlist = []
var retrieved = "newartists"
var send_queue = []
#signals
# warning-ignore:unused_signal
signal login(status)
# warning-ignore:unused_signal
signal interface(type,data)
# warning-ignore:unused_signal
#signal command(type,data)
# warning-ignore:unused_signal
signal linked()
signal userLoaded()
signal socket_returns(data)
signal accountdata(data)
signal profiledata(data)
signal chatdata(data)
signal sent_chat(data)
signal chat_history(data)
signal new_chat()
signal keydata(data)
signal conversations(data)
signal connections(data)
signal user_status(data)
signal request_status(data)
signal request_update(data)
signal ChatMessageRecieved(data)
signal post(data)
signal comment(data)
signal account_created(data)
signal creator_created(data)
signal creatorData(data)
signal tracks(data)
signal genres(data)
signal artists(data)
signal new_tracks(data)
signal new_artists(data)
# warning-ignore:unused_signal
signal queue_updated(data)
signal historydata(data)
# warning-ignore:unused_signal
signal imagestored(data)
signal image_data(data)
# warning-ignore:unused_signal
signal update_loop(last)
var dev_steem = ""
var dev_postingkey = ""
var appdefaults
var threadedServer = StreamPeerTCP.new()
var server = StreamPeerTCP.new()
var websocket = WebSocketClient.new()
export var retry = 15
var retried = 0
# Called when the node enters the scene tree for the first time.
# Default mode is set to login for obvious reasons.
# Current interface options include:
# login: typical login interface also includes the new account creation dialogs
# steem: Interface to allow users to connect their game to the steem blockchain for cloud services.
func _ready():
appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
if mode == "websocket":
print("connecting websocket signals")
websocket.connect("connection_closed", self, "_closed")
websocket.connect("connection_error", self, "_closed")
websocket.connect("connection_established", self, "_connected")
# This signal is emitted when not using the Multiplayer API every time
# a full packet is received.
# Alternatively, you could check get_peer(1).get_available_packets() in a loop.
websocket.connect("data_received", self, "_on_data")
# Initiate connection to the given URL.
var err = websocket.connect_to_url("ws://"+openseed+":8765")
if err != OK:
print("Unable to connect")
set_process(false)
#if mode == "socket":
# warning-ignore:return_value_discarded
$Timer.connect("timeout",self,"update_loop")
$Timer.start()
func update_loop():
if OpenSeed.token:
if send_queue.size() > 0:
openSeedRequest("queue",[])
waiting = true
else:
openSeedRequest("getConversations",[])
waiting = true
else:
if send_queue.size() > 0:
openSeedRequest("queue",[])
waiting = true
func send(data,priority):
var checked = parse_json(data)
if typeof(checked) == TYPE_DICTIONARY:
match priority:
1:
if send_queue.find(str(data)) == -1:
if send_queue.size() >= 1:
send_queue.insert(0,data)
else:
send_queue.append(data)
2:
if send_queue.find(str(data)) == -1:
if send_queue.size() >= 1:
send_queue.insert(1,data)
else:
send_queue.append(data)
3:
if send_queue.find(str(data)) == -1:
if send_queue.size() >= 2:
send_queue.insert(2,data)
else:
send_queue.append(data)
6:
if send_queue.find(str(data)) == -1:
send_queue.push_back(data)
_:
if send_queue.find(str(data)) == -1:
send_queue.append(data)
else:
print(data)
print("json error")
return 1
func openSeedRequest(type,data):
appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
match type:
# Verifies the login creditials of an account on Openseed and reports back pass/fail/nouser.
"verify_account":
send('{"act":"account_check",'+appdefaults+',"account":"'+data[0]+'","passphrase":"'+data[1]+'"}',2)
# Creates user based on the provided information. This user is added to the Openseed service.
"create_account":
send('{"act":"create_account",'+appdefaults+',"account":"'+data[0]+'","passphrase":"'+data[1]+'","email":"'+data[2]+'" }',2)
"loadUser":
loadUserData()
"getProfile":
send('{"act":"get_profile",'+appdefaults+',"account":"'+data[0]+'"}',2)
"setProfile":
send('{"act":"set_profile",'+appdefaults+',"token":"'+data[0]+',"openseed":'+data[1]+',"extended":'+
data[2]+',"appdata":'+data[3]+',"misc":"'+data[4]+'","imports":'+data[5]+',"type":"'+data[6]+'"}',2)
"createCreator":
send('{"act":"create_creator_account",'+appdefaults+',"creatorName":"'+data[0]+'","contactName":"'+data[1]+'","contactEmail":"'+data[2]+'","openseed":"'+data[3]+'"}',3)
"getCreator":
send('{"act":"creator_check",'+appdefaults+',"name":"'+data[0]+'","token":"'+data[1]+'"}',3)
"loadProfile":
loadUserProfile(data[0])
"history":
if OpenSeed.token != "" and data[0] != "":
send('{"act":"get_history",'+appdefaults+',"account":"'+data[0]+'","apprange":"'+data[1]+'","count":"'+data[2]+'"}',3)
"get_image":
if data:
send('{"act":"get_image",'+appdefaults+',"image":"'+data[0]+'","thetype":"url","quality":"'+data[1]+'"}',2)
"updateStatus":
if OpenSeed.token != "":
send('{"act":"set_status",'+appdefaults+',"token":"'+OpenSeed.token+'","status":'+data[0]+'}',2)
"getStatus":
if OpenSeed.token != "" and data[0] != "":
send('{"act":"get_status",'+appdefaults+',"account":"'+data[0]+'"}',2)
###################
#
# Social Functions
#
###################
"getRequests":
if !thread.is_active():
print("getting Requests")
"get_key":
send('{"act":"get_key",'+appdefaults+',"thetype":"1","room":"'+data[1]+'","users":"'+data[0]+'","token":"'+OpenSeed.token+'"}',2)
"get_room_by_attendees":
send('{"act":"find_room_by_attendees",'+appdefaults+',"token":"'+OpenSeed.token+'","attendees":"'+str(data)+'","create":"1"}',2)
"get_chat_history":
send('{"act":"get_chat_history",'+appdefaults+',"token":"'+OpenSeed.token+'","room":"'+data[0]+'","count":"'+str(data[1])+'","last":"'+str(data[2])+'"}',2)
"get_chat":
if data[0]:
send('{"act":"get_chat",'+appdefaults+',"token":"'+OpenSeed.token+'","room":"'+data[0]+'","last":"'+str(data[1])+'"}',2)
"getConversations":
send('{"act":"get_conversations",'+appdefaults+',"token":"'+OpenSeed.token+'"}',2)
"get_connections":
if data[0] != "":
send('{"act":"get_connections",'+appdefaults+',"account":"'+data[0]+'","hive":false}',2)
##################
#
# Music functions
#
##################
"get_genres":
send('{"act":"get_genres",'+appdefaults+'}',6)
"get_genre":
send('{"act":"get_genre",'+appdefaults+',"genre":"'+data[0]+'","count":"50"}',6)
"get_new_tracks":
send('{"act":"get_new_tracks",'+appdefaults+'}',6)
"get_new_musicians":
send('{"act":"get_new_musicians",'+appdefaults+'}',6)
"muscian_search":
send('{"act":"artist_search",'+appdefaults+',"author":"'+data[0]+'"}',3)
####################
#
# Hive Functions
#
####################
"get_hive_account":
send('{"act":"get_hive_account",'+appdefaults+',"account":"'+data[0]+'"}',2)
"get_hive_post":
send('{"act":"get_hive_post",'+appdefaults+',"author":"'+data[0]+'","permlink":"'+data[1]+'"}',2)
"set_hive_follow":
send('{"act":"follow",'+appdefaults+',"token":"'+data[0]+'","follow":"'+data[1]+'"}',4)
"send_hive_tokens":
send('{"act":"payment",'+appdefaults+',"token":"'+data[0]+'","amount":"'+data[1]+'","to":"'+data[2]+'","for":"'+data[3]+'"}',4)
"send_hive_like":
send('{"act":"like_hive_post",'+appdefaults+',"token":"'+data[0]+'","author":"'+data[1]+'","post":"'+data[2]+'","percent":100}',2)
"send_hive_comment":
send('{"act":"post_hive_comment",'+appdefaults+',"token":"'+data[0]+'","author":"'+data[1]+'","post":"'+data[2]+'","comment":"'+data[3]+'"}',2)
"queue":
if mode == "socket":
if !thread.is_active():
#var msg = send_queue[0]
var msg = "msg="+appPub+"<::>"+simp_crypt(appId,send_queue[0])+"<::>"
thread.start(OpenSeed,"get_from_socket_threaded",[msg,"queued_event"])
if mode == "web":
#var msg = "msg="+appPub+"<::>"+simp_crypt(appId,send_queue[0])+"<::>"
var msg = "msg="+appPub+"<::>"+send_queue[0]+"<::>"
#var msg = "msg="+send_queue[0]
var headers = []
#$HTTPRequest.connect("request_completed",self,"")
if waiting == false:
$HTTPRequest.request("http://api.openseed.solutions/",headers,false,HTTPClient.METHOD_POST,msg)
waiting = true
#thread.start(OpenSeed,"get_from_socket_threaded",[msg,"queued_event"])
pass
if mode == "websocket":
#var msg = "msg="+send_queue[0]
var msg = "msg="+appPub+"<::>"+simp_crypt(appId,send_queue[0])+"<::>"
get_from_websocket(msg)
pass
func get_from_websocket(data):
#print("using websocket")
if websocket.get_connection_status() != 2:
print("Lost connection: ")
if websocket.get_connection_status() == 0:
var err = websocket.connect_to_url("ws://"+openseed+":8765")
if err != OK:
print("Unable to connect")
#set_process(false)
#else:
#websocket.set_buffers()
#websocket.get_peer(1).put_packet(data.to_utf8())
#return(websocket.get_peer(1).get_packet().get_string_from_utf8())
elif websocket.get_connection_status() == 2:
websocket.get_peer(1).put_packet(data.to_utf8())
#return(websocket.get_peer(1).get_packet().get_string_from_utf8())
#print(data)
var fullreturn = ""
var _timeout = 18000
return fullreturn
func _closed(was_clean = false):
# was_clean will tell you if the disconnection was correctly notified
# by the remote peer before closing the socket.
print("Closed, clean: ", was_clean)
#set_process(false)
func _connected(proto = ""):
# This is called on connection, "proto" will be the selected WebSocket
# sub-protocol (which is optional)
print("Connected with protocol: ", proto)
# You MUST always use get_peer(1).put_packet to send data to server,
# and not put_packet directly when not using the MultiplayerAPI.
#websocket.get_peer(1).put_packet("Test packet".to_utf8())
func _on_data():
# Print the received packet, you MUST always use get_peer(1).get_packet
# to receive data from server, and not get_packet directly when not
# using the MultiplayerAPI.
var returns = websocket.get_peer(1).get_packet().get_string_from_utf8()
var decrypt = simp_decrypt(appId,returns).strip_edges()
_on_OpenSeed_socket_returns(["queue",decrypt])
#print("Got data from server: "+decrypt)
func _process(_delta):
# Call this in _process or _physics_process. Data transfer, and signals
# emission will only happen when calling this function.
websocket.poll()
func _exit_tree():
websocket.disconnect_from_host()
func get_from_socket_threaded(data):
# warning-ignore:unused_variable
var fullreturn = ""
var _timeout = 18000
var BUFF_SIZE = 4096
var therest = ""
if !threadedServer.is_connected_to_host():
threadedServer.connect_to_host(openseed, 8688)
while threadedServer.get_status() != 2:
_timeout -= 1
if threadedServer.is_connected_to_host():
if threadedServer.get_status() == 2 :
threadedServer.put_data(data[0].to_utf8())
var fromserver = threadedServer.get_partial_data(BUFF_SIZE)
var size = threadedServer.get_available_bytes()
if size > 0:
if size < BUFF_SIZE:
therest = threadedServer.get_partial_data(size)[1].get_string_from_utf8()
else:
var whatsleft = size
while whatsleft > BUFF_SIZE:
therest += threadedServer.get_partial_data(BUFF_SIZE)[1].get_string_from_utf8()
whatsleft -= BUFF_SIZE
if whatsleft > 0:
therest += threadedServer.get_partial_data(whatsleft)[1].get_string_from_utf8()
fullreturn = fromserver[1].get_string_from_utf8() + therest
else:
fullreturn = fromserver[1].get_string_from_utf8()
#print(fullreturn)
var decrypt = simp_decrypt(appId,fullreturn).strip_edges()
#var decrypt = fullreturn
if len(decrypt) >= 0:
call_deferred("returned_from_socket",data[1])
if decrypt[-1] != "}":
print("Incomplete return")
#print(decrypt)
return '{"server":"incomplete return error"}'
else:
return (decrypt)
func returned_from_socket(type):
#print(type)
var socket = thread.wait_to_finish()
emit_signal("socket_returns",[type,socket])
func _on_OpenSeed_socket_returns(data):
var jsoned
if data[1]:
jsoned = parse_json(data[1])
if typeof(jsoned) == TYPE_DICTIONARY:
if jsoned.has("profile"):
if debug == true:
retried = 0
print("finished "+send_queue[0])
if OpenSeed.profile_name == "User":
saveUserProfile(data[1])
loadUserProfile(OpenSeed.username)
else:
if jsoned["profile"].has("username"):
emit_signal("profiledata",[jsoned["profile"]["username"],jsoned["profile"]])
if jsoned.has("account"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("accountdata",jsoned["account"])
if jsoned.has("creator_account"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("creator_created",jsoned["creator_account"])
if jsoned.has("creator_info"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("creatorData",jsoned["creator_info"])
if jsoned.has("hive"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
if jsoned["hive"].has("profile"):
emit_signal("profiledata",[jsoned["username"],jsoned["hive"]])
if jsoned["hive"].has("app"):
emit_signal("profiledata",[jsoned["username"],jsoned["hive"]["app"]])
if jsoned.has("history"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("historydata",jsoned["history"])
if jsoned.has("image"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("image_data",jsoned["image"])
add_to_image_store(jsoned["image"]["source"],jsoned["image"]["quality"],jsoned["image"]["hash"])
########
#
# Chat
#
########
if jsoned.has("chat"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("chatdata",jsoned["chat"])
if jsoned.has("chat_history"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("chat_history",jsoned["chat_history"])
if jsoned.has("chat_response"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("sent_chat",data[1])
if jsoned.has("conversations"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
if str(conversations) != str(jsoned["conversations"]):
emit_signal("new_chat")
conversations = jsoned["conversations"]
emit_signal("conversations",conversations)
if jsoned.has("lock"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("keydata",jsoned["lock"])
########
#
# Music
#
########
if jsoned.has("newtracks"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("new_tracks",jsoned["newtracks"])
if jsoned.has("new_musicians"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("new_artists",jsoned["new_musicians"])
if jsoned.has("genre_tracks"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("tracks",jsoned["genre_tracks"])
if jsoned.has("genres"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("genres",jsoned["genres"])
########
#
# Social
#
########
if jsoned.has("status"):
retried = 0
#print(jsoned)
if debug == true:
print("finished "+send_queue[0])
emit_signal("user_status",[jsoned["status"]["data"]["chat"],jsoned["status"]["account"]])
if jsoned.has("request"):
retried = 0
# print(jsoned)
if debug == true:
print("finished "+send_queue[0])
emit_signal("request_status",[jsoned["request"],jsoned["account"]])
if jsoned.has("request_status"):
retried = 0
# print(jsoned)
if debug == true:
print("finished "+send_queue[0])
emit_signal("request_update",jsoned["request_status"])
if jsoned.has("connections"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("connections",jsoned["connections"])
###################
#
# Hive
#
###################
if jsoned.has("hive_post"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
print(jsoned["hive_post"])
emit_signal("post",jsoned["hive_post"])
if jsoned.has("liked_hive_post"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
if jsoned.has("hive_comment"):
retried = 0
if debug == true:
print("finished "+send_queue[0])
emit_signal("comment",jsoned["hive_comment"])
if jsoned.has("server"):
retried += 1
print(jsoned)
print("error in " + send_queue[0])
if debug == true:
print("error in " + send_queue[0])
print(retried)
else:
#if debug == true:
#print("removing "+send_queue[0])
send_queue.remove(0)
else:
print("not JSON "+data[1])
send_queue.remove(0)
if retried >= retry:
retried = 0
if debug == true:
print("failed at "+send_queue[0])
print("got "+data[1])
send_queue.remove(0)
func _on_link_linked():
pass # Replace with function body.
# In this function we send OpenSeed a request to add new data to the leaderboard. Taking two variables u for user and d for the data.
# The data is then reformated into a transmitable json like format for get_leaderboard to parse.
# Note the need for a steem account (called steem) and a postingkey. As a developer you have the choice to use your own postingKey or require the user to use theirs.
# a small fee 0.001 STEEM is required to post the memo on openseeds account to store the information on the chain.
#func update_leaderboard(u,d):
# appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
# var dataformat = '{\\"'
# var datapoint = 0
# while datapoint < len(d):
# var repoint = d[datapoint].split(":")[0]+'\\":\\"'+d[datapoint].split(":")[1]
# dataformat = str(dataformat)+str(repoint)
# if datapoint+1 < len(d):
# dataformat = str(dataformat)+'\\",\\"'
# datapoint += 1
# dataformat = dataformat+'\\"}'
# var response = get_from_socket('{"act":"toleaderboard",'+appdefaults+',"username":"'+str(u)+'","data":"'+str(dataformat)+'","steem":"'+str(dev_steem)+'","postingkey":"'+str(dev_postingkey)+'"}')
# return response
# warning-ignore:unused_argument
#func get_leaderboard(number):
# var scores = get_from_socket('{"act":"getleaderboard",'+appdefaults+'}')
# return scores
func set_history(action_type,action):
var act = ""
var act_type = ""
var data = ""
var format = ""
match action_type:
"program_start":
act_type = 1
format = action
data ='{"'+action_type+'":"'+format+'"}'
"program_stop":
act_type = 2
"playing":
act_type = 3
if typeof(action) == TYPE_ARRAY:
format = '{"song":"'+action[0]+'","artist":"'+action[1]+'"}'
data ='{"'+action_type+'":'+format+'}'
else:
format = ""
"purchase":
act_type = 4
format = action
data ='{"'+action_type+'":"'+format+'"}'
"download":
act_type = 5
format = action
data ='{"'+action_type+'":"'+format+'"}'
"linked":
act_type = 6
format = action
data ='{"'+action_type+'":"'+format+'"}'
_:
act_type = 0
format = action
data ='{"'+action_type+'":"'+format+'"}'
var packet = '"act":"update_history",'+appdefaults+',"type":"'+str(act_type)+'","account":"'+str(OpenSeed.token)+'"'
if format != "":
send('{'+packet+',"data":'+str(data)+'}',5)
func saveUserData():
var file = File.new()
var key = appId+devId+str(123456)
var content = '{"usertoken":"'+str(token)+'","username":"'+str(username)+'","steemaccount":"'+str(steem)+'","postingkey":"'+str(postingkey)+'"}'
file.open_encrypted_with_pass("user://openseed.dat", File.WRITE,key)
file.store_string(content)
file.close()
func saveUserProfile(data):
var file = File.new()
file.open("user://"+username+"profile.dat",File.WRITE)
file.store_string(data)
file.close()
func loadUserProfile(account):
appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
var file = File.new()
var profile
if file.file_exists("user://"+account+"profile.dat"):
file.open("user://"+account+"profile.dat",File.READ)
var content = parse_json(file.get_as_text())["profile"]
if content:
profile_name = content["openseed"]["name"]
profile_about = content["extended"]["about"]
if content["extended"].has("profile_img"):
profile_image = content["extended"]["profile_img"]
else:
profile_image = ""
profile_email = content["openseed"]["email"]
profile_phone = content["openseed"]["phone"]
emit_signal("userLoaded")
else:
print("no profile found")
openSeedRequest("getProfile",[account])
file.close()
else:
print("no profile found")
openSeedRequest("getProfile",[account])
return profile_name
func loadUserData():
var file = File.new()
var key = appId+devId+str(123456)
file.open_encrypted_with_pass("user://openseed.dat", File.READ,key)
var content = parse_json(file.get_as_text())
file.close()
if content:
username = content["username"]
token = content["usertoken"]
steem = content["steemaccount"]
postingkey = content["postingkey"]
openSeedRequest("updateStatus",['{"chat":"Online"}'])
emit_signal("userLoaded")
return content
func check_ipfs():
var ipfs_output = []
var ipfs_path = ""
var file = File.new()
if OS.get_name() == "X11":
if file.file_exists("/usr/bin/ipfs"):
ipfs_path = "/usr/bin/ipfs"
elif file.file_exists("/snap/bin/ipfs"):
ipfs_path = "/snap/bin/ipfs"
if ipfs_path != "":
ipfs = ipfs_path
# warning-ignore:return_value_discarded
OS.execute("ps",["-e"],true,ipfs_output)
print(ipfs_output[0].find("ipfs"))
if ipfs_output[0].find("ipfs") == -1:
print(OS.execute(ipfs_path,["daemon","--routing=dhtclient"],false))
###########################################################################
#
# Social Functions (Profiles, Requests, Connections, etc,)
#
###########################################################################
func get_openseed_account(account):
appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
openSeedRequest("getProfile",[account])
func get_openseed_account_status(account):
appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
var status = '{"act":"get_status",'+appdefaults+',"account":"'+account+'"}'
send(status,6)
###########################################################################
#
# Chat Functions
#
###########################################################################
func create_chatroom(title,attendees):
var command = '{"act":"create_chatroom","appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+ \
'","token":"'+OpenSeed.token+'","title":"'+str(title)+'","attendees":"'+attendees+'"}'
send(command,3)
#func find_room_by_attendess(attendees):
# var command = parse_json(get_from_socket('{"act":"find_room_by_attendees","appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+ \
# '","token":"'+OpenSeed.token+'","attendees":"'+attendees+'","create":"1"}'))
# return command
# warning-ignore:shadowed_variable
func send_chat(message,room):
var command = '{"act":"send_chat","appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+ \
'","token":"'+OpenSeed.token+'","room":"'+str(room)+'","message":"'+message+'"}'
if send_queue.find(str(command)) == -1:
send(command,1)
return "queued"
##############################################################################
#
# Connection functions
#
#############################################################################
# warning-ignore:unused_argument
func send_request(account,response):
var command = '{"act":"send_request","appPub":"'+ \
str(appPub)+'","devPub":"'+str(devPub)+ \
'","token":"'+OpenSeed.token+'","account":"'+account+'"}'
send(command,5)
func set_request(account,response):
var command = '{"act":"set_request","appPub":"'+ \
str(appPub)+'","devPub":"'+str(devPub)+ \
'","token":"'+OpenSeed.token+'","account":"'+account+'","response":"'+response+'"}'
send(command,2)
func get_request_status(account):
var command = '{"act":"get_request_status","appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+ \
'","token":"'+OpenSeed.token+'","account":"'+account+'"}'
send(command,6)
func find_by_attendees(attendees):
var room = ""
for convo in conversations:
var list = convo["attendees"].split(",")
for person in attendees:
var indx = 0
for p in list:
if p == person:
list.remove(indx)
indx += 1
if list.size() == 0:
room = convo["room"]
break
return room
##################################################
#
# Encryption Functions
#
##################################################
func get_keys_for(users,room):
var key = ""
for test in keys:
if test["room"] == room:
key = test["key"]
break
if key == "":
appdefaults = '"appPub":"'+str(appPub)+'","devPub":"'+str(devPub)+'"'
openSeedRequest("get_key",[users,room])
else:
emit_signal("keydata",{"key":key,"room":room})
return key
func simp_crypt(key,raw_data):
if debug == true:
#print("encrypting "+raw_data)
#print("using "+key)
pass
var num_array = []
for c in key:
if int(c) and int(c) % 2 == 0:
num_array.append(c)
while len(num_array) <= len(raw_data):
num_array += num_array
num_array += num_array
var secret = ""
var datanum = 0
var digits = ""
var key_digits = ""
var key_stretch = key
var keystring = ""
#//lets turn it into integers first//
for t in raw_data:
var c = t.ord_at(0)
digits += str(c)+" "
var data = digits
if key_stretch != "":
if len(data)> len(key_stretch):
while len(key_stretch) < len(data):
key_stretch = key_stretch + key
key_stretch = key_stretch.substr(0,len(data))
data = data.split(" ")
for b in key_stretch:
var i = b.ord_at(0)
key_digits += str(i)+" "
key_digits = key_digits.split(" ")
var keynum = 0
for d in data:
if d:
if int(d) == int(key_digits[keynum]):
secret += char(int(d))
else:
var combine = 0
if int(num_array[keynum]) % 2 == 0:
combine = int(d) + int(key_digits[keynum])
else:
combine =int(d) * int(num_array[keynum])
secret = secret + char(combine)
keynum += 1
if debug == true:
#print("encrypted as "+secret.replace(" ","zZz"))
pass
return secret.replace(" ","zZz").strip_edges()
func simp_decrypt(key,raw_data):
if debug == true:
#print("decrypting "+raw_data)
#print("using "+key)
pass
if key == "":
print("no key")
return
var num_array = []
for c in key:
if int(c) and int(c) % 2 == 0:
num_array.append(c)
while len(num_array) <= len(raw_data):
num_array += num_array
num_array += num_array
if debug == true:
#print("num array: ",num_array)
pass