|
| 1 | +import scratchattach as sa |
| 2 | +from scratchattach.cloud.cloud import CustomCloud |
| 3 | +import logging |
| 4 | +from rich.traceback import install |
| 5 | + |
| 6 | +install(show_locals=True) |
| 7 | + |
| 8 | +# Init Server & Cloud Events |
| 9 | + |
| 10 | +server_ip = '127.0.0.1' |
| 11 | +server_port_a = 8080 |
| 12 | +server_port_b = 8765 |
| 13 | +project_id="1321224718" |
| 14 | + |
| 15 | +server = sa.init_cloud_server("127.0.0.1", |
| 16 | + server_port_a, |
| 17 | + length_limit=65536, |
| 18 | + allow_non_numeric=True, |
| 19 | + whitelisted_projects=[project_id], |
| 20 | + allow_nonscratch_names=False, |
| 21 | + blocked_ips=["127.0.0.2"], |
| 22 | + sync_players=True, |
| 23 | + log_var_sets=True |
| 24 | + ) |
| 25 | +server.start() |
| 26 | + |
| 27 | + |
| 28 | +banned_cloud = CustomCloud(project_id='1234567', |
| 29 | + cloud_host=f"ws://{server_ip}:{server_port_a}", |
| 30 | + username = "Boss_1s", |
| 31 | + length_limit = None, |
| 32 | + allow_non_numeric = True, |
| 33 | + _session = None, |
| 34 | + header = None, |
| 35 | + cookie = None, |
| 36 | + origin = None, |
| 37 | + print_connect_messages = True |
| 38 | + ) |
| 39 | + |
| 40 | +bad_user_name_cloud = CustomCloud(project_id=project_id, |
| 41 | + cloud_host=f"ws://{server_ip}:{server_port_a}", |
| 42 | + username = "Boss_asdfghjkl", |
| 43 | + length_limit = None, |
| 44 | + allow_non_numeric = True, |
| 45 | + _session = None, |
| 46 | + header = None, |
| 47 | + cookie = None, |
| 48 | + origin = None, |
| 49 | + print_connect_messages = True |
| 50 | + ) |
| 51 | + |
| 52 | +cloud = CustomCloud(project_id=project_id, |
| 53 | + cloud_host=f"ws://{server_ip}:{server_port_a}", |
| 54 | + username = "Boss_1s", |
| 55 | + length_limit = None, |
| 56 | + allow_non_numeric = True, |
| 57 | + _session = None, |
| 58 | + header = None, |
| 59 | + cookie = None, |
| 60 | + origin = None, |
| 61 | + print_connect_messages = True |
| 62 | + ) |
| 63 | + |
| 64 | +no_user_cloud = CustomCloud(project_id=project_id, |
| 65 | + cloud_host=f"ws://{server_ip}:{server_port_a}", |
| 66 | + username = None, |
| 67 | + length_limit = None, |
| 68 | + allow_non_numeric = True, |
| 69 | + _session = None, |
| 70 | + header = None, |
| 71 | + cookie = None, |
| 72 | + origin = None, |
| 73 | + print_connect_messages = True |
| 74 | + ) |
| 75 | + |
| 76 | +no_project_cloud = CustomCloud(project_id=None, |
| 77 | + cloud_host=f"ws://{server_ip}:{server_port_a}", |
| 78 | + username="Boss_1s", |
| 79 | + length_limit = None, |
| 80 | + allow_non_numeric = True, |
| 81 | + _session = None, |
| 82 | + header = None, |
| 83 | + cookie = None, |
| 84 | + origin = None, |
| 85 | + print_connect_messages = True |
| 86 | + ) |
| 87 | + |
| 88 | +banned_cloud_events=banned_cloud.events() |
| 89 | +bad_user_name_cloud_events=bad_user_name_cloud.events() |
| 90 | +cloud_events=cloud.events() |
| 91 | +no_user_cloud_events=no_user_cloud.events() |
| 92 | +no_project_cloud_events=no_project_cloud.events() |
| 93 | + |
| 94 | +# Test with ssl and make sure it works |
| 95 | + |
| 96 | +server = sa.init_ssl_cloud_server("127.0.0.1", |
| 97 | + server_port_b, |
| 98 | + length_limit=65536, |
| 99 | + allow_non_numeric=True, |
| 100 | + whitelisted_projects=[project_id], |
| 101 | + allow_nonscratch_names=False, |
| 102 | + blocked_ips=["127.0.0.2"], |
| 103 | + sync_players=True, |
| 104 | + log_var_sets=True, |
| 105 | + certfile="certfile.pem", |
| 106 | + keyfile="keyfile.pem" |
| 107 | + ) |
| 108 | +server.start() |
| 109 | + |
| 110 | + |
| 111 | +banned_cloud = CustomCloud(project_id='1234567', |
| 112 | + cloud_host=f"wss://{server_ip}:{server_port_b}", |
| 113 | + username = "Boss_1s", |
| 114 | + length_limit = None, |
| 115 | + allow_non_numeric = True, |
| 116 | + _session = None, |
| 117 | + header = None, |
| 118 | + cookie = None, |
| 119 | + origin = None, |
| 120 | + print_connect_messages = True |
| 121 | + ) |
| 122 | + |
| 123 | +bad_user_name_cloud = CustomCloud(project_id=project_id, |
| 124 | + cloud_host=f"wss://{server_ip}:{server_port_b}", |
| 125 | + username = "Boss_asdfghjkl", |
| 126 | + length_limit = None, |
| 127 | + allow_non_numeric = True, |
| 128 | + _session = None, |
| 129 | + header = None, |
| 130 | + cookie = None, |
| 131 | + origin = None, |
| 132 | + print_connect_messages = True |
| 133 | + ) |
| 134 | + |
| 135 | +cloud = CustomCloud(project_id=project_id, |
| 136 | + cloud_host=f"wss://{server_ip}:{server_port_b}", |
| 137 | + username = "Boss_1s", |
| 138 | + length_limit = None, |
| 139 | + allow_non_numeric = True, |
| 140 | + _session = None, |
| 141 | + header = None, |
| 142 | + cookie = None, |
| 143 | + origin = None, |
| 144 | + print_connect_messages = True |
| 145 | + ) |
| 146 | + |
| 147 | +no_user_cloud = CustomCloud(project_id=project_id, |
| 148 | + cloud_host=f"wss://{server_ip}:{server_port_b}", |
| 149 | + username = None, |
| 150 | + length_limit = None, |
| 151 | + allow_non_numeric = True, |
| 152 | + _session = None, |
| 153 | + header = None, |
| 154 | + cookie = None, |
| 155 | + origin = None, |
| 156 | + print_connect_messages = True |
| 157 | + ) |
| 158 | + |
| 159 | +no_project_cloud = CustomCloud(project_id=None, |
| 160 | + cloud_host=f"wss://{server_ip}:{server_port_b}", |
| 161 | + username="Boss_1s", |
| 162 | + length_limit = None, |
| 163 | + allow_non_numeric = True, |
| 164 | + _session = None, |
| 165 | + header = None, |
| 166 | + cookie = None, |
| 167 | + origin = None, |
| 168 | + print_connect_messages = True |
| 169 | + ) |
| 170 | + |
| 171 | +banned_cloud_events=banned_cloud.events() |
| 172 | +bad_user_name_cloud_events=bad_user_name_cloud.events() |
| 173 | +cloud_events_b=cloud.events() |
| 174 | +no_user_cloud_events=no_user_cloud.events() |
| 175 | +no_project_cloud_events=no_project_cloud.events() |
| 176 | + |
| 177 | +@cloud_events_b.event |
| 178 | +def on_connect(): |
| 179 | + print("Connected to cloud server with SSL") |
| 180 | + |
| 181 | +@cloud_events_b.event |
| 182 | +def on_disconnect(): |
| 183 | + print("Disconnected from cloud server with SSL") |
| 184 | + |
| 185 | +cloud_events_b.start() |
0 commit comments