{"action":"created","comment":{"url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/comments/155180136","pull_request_review_id":81455011,"id":155180136,"diff_hunk":"@@ -0,0 +1,922 @@\n+package Network\n+\n+import SyncSimple\n+import Table\n+import ErrorHandling\n+import MoriUtil\n+\n+// max amount to be written/read/synced per an execution to avoid hitting the OP limit\n+// this value can be higher if Wurst is compiled without stack traces and with all optimizations turned on\n+// and even higher with safety checks off\n+@configurable constant integer DATA_PER_EXECUTE = 256\n+// max length of a GC key\n+// you may fine-tune it as you see fit to see what works faster\n+@configurable constant integer MAX_CHARACTERS_PER_KEY = 3\n+// setting this to false will optimize out all safety checks...\n+// only disable this if you are 100% sure your code works correctly\n+@configurable constant boolean SAFETY_CHECKS_ENABLED = true\n+\n+//TODO: I just realized that we can eliminate some delay by sending metadata and the first round together\n+// and avoid one round-trip, essentially reducing transmission time for small payloads up to two times\n+\n+/********************************************************************************\n+\tNetwork library v1.0 by MoriMori.\n+\n+\tBased on TriggerHappy's Sync library.\n+\n+\tRationale:\n+\t\tThis library can be used to send arbitrary amounts of integer, real, boolean\n+\t\tand string data from one player to the rest.\n+\n+\t\tLike SyncSimple, it abuses the fact that all network actions in WC3 are\n+\t\tsequential, and are received by players in the same order that are sent in.\n+\n+\t\tIt uses the SyncStored* natives of the gamecache to send data to other players\n+\t\tfrom the sender, and then uses SyncSimple to send a 'finish' event, that will\n+\t\tonly be received by other players after they have also received all sync data.\n+\n+\t\tThe Network class provides 4 independent streams of data:\n+\t\t\tintegers,\n+\t\t\treals,\n+\t\t\tbooleans,\n+\t\t\tstrings\n+\n+\t\teach of which can be written/read to using the relevant \n+\t\tmethods of the DataStream class.\n+\n+\t\tBefore sending the data, the sender populates the DataStream with the data that\n+\t\tthey want to send, then Network.start() is called, as well as Network.onFinish(callback)\n+\t\tand data is received from the same buffer inside the callback when it has all been received.\n+\n+\t\tRead SyncSimple docs for a slightly more in-depth overview of this particular\n+\t\tpeculiarity of WC3.\n+\n+\tUsage:\n+\t\t1. Create a new Network object using:\n+\t\t\t// sender is the player to receive data from\n+\t\t\tlet network = new Network(sender)\n+\n+\t\t2. Queue some data for sending from the sender. You can write as much as you need, there is no limit:\n+\t\t\tif localPlayer == sender\n+\t\t\t\t// keep in mind that before you start sending data,\n+\t\t\t\t// network.getData() is locked in a WRITE-ONLY MODE\n+\t\t\t\tval stream = network.getData()\n+\t\t\t\tstream.writeInteger(...)\n+\t\t\t\tstream.writeReal(...)\n+\t\t\t\tstream.writeString(...)\n+\t\t\t\t...\n+\n+\t\t3. To start sending the data, simply call:\n+\t\t\tnetwork.start()\t\t\t\n+\t\t\t// this will start the transmission\n+\t\t\t// keep in mind, that after you call this, you MUST NOT write/read to network.getData()\n+\t\t\t// as it is locked while the data is syncing\n+\t\t\n+\t\t4. To receive the data, specify the callback and read the data inside it:\n+\t\t\tnetwork.onFinish((stream) -> begin\n+\t\t\t\t// here, network.getData() is locked in a READ-ONLY MODE and\n+\t\t\t\t// you can only READ from it\n+\t\t\t\tvar int = stream.readInteger()\n+\t\t\t\tvar real = stream.readReal()\n+\t\t\t\tvar string = stream.readString()\n+\t\t\t\t...\n+\t\t\tend)\n+\n+\t\t\tWARNING: Network is a one-time use class, and is automatically\n+\t\t\tdestroyed upon finishing. If you need to send another transmission,\n+\t\t\tcreate a new one.\n+\t\t\tYou are also expected to read all data immediately after receiving it,\n+\t\t\tas the DataStream is destroyed together with Network. \n+\n+\t\t5. When writing and reading, keep in mind that you MUST read data from\n+\t\tthe stream in the same order that it was written, for each independent type.\n+\t\tThat means that integers have to be written/read in the same order, same for\n+\t\tbooleans, strings and reals.\n+\t\tIf you need data of non-fixed length, use a static packet structure\n+\t\twith length fields, like so:\n+\t\t\tvar field1 = stream.readInteger()\n+\t\t\tvar field2 = stream.readInteger()\n+\t\t\tvar length = stream.readInteger()\n+\t\t\tfor i = 0 to length - 1\n+\t\t\t\tsomeArray[i] = stream.readInteger()\n+\n+\t\t6. Alternatively, your classes can implement Serializable, like so:\n+\t\t\tclass MyClass implements Serializable\n+\t\t\t\tinteger field1 = ...\n+\t\t\t\tinteger field2 = ...\n+\t\t\t\tinteger field3 = ...\n+\t\t\t\tstring field4 = ...\n+\n+\t\t\t\t// optional stream-constructor\n+\t\t\t\tconstruct (DataStream stream)","path":"wurst/network/Network.wurst","position":111,"original_position":111,"commit_id":"938205f1adaa3adab361dcd137a119f60377899f","original_commit_id":"938205f1adaa3adab361dcd137a119f60377899f","user":{"login":"SamuelMoriarty","id":3159552,"avatar_url":"https://avatars0.githubusercontent.com/u/3159552?v=4","gravatar_id":"","url":"https://api.github.com/users/SamuelMoriarty","html_url":"https://github.com/SamuelMoriarty","followers_url":"https://api.github.com/users/SamuelMoriarty/followers","following_url":"https://api.github.com/users/SamuelMoriarty/following{/other_user}","gists_url":"https://api.github.com/users/SamuelMoriarty/gists{/gist_id}","starred_url":"https://api.github.com/users/SamuelMoriarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamuelMoriarty/subscriptions","organizations_url":"https://api.github.com/users/SamuelMoriarty/orgs","repos_url":"https://api.github.com/users/SamuelMoriarty/repos","events_url":"https://api.github.com/users/SamuelMoriarty/events{/privacy}","received_events_url":"https://api.github.com/users/SamuelMoriarty/received_events","type":"User","site_admin":false},"body":"Whoops, my bad","created_at":"2017-12-06T09:15:08Z","updated_at":"2017-12-06T09:15:08Z","html_url":"https://github.com/wurstscript/WurstStdlib2/pull/19#discussion_r155180136","pull_request_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/comments/155180136"},"html":{"href":"https://github.com/wurstscript/WurstStdlib2/pull/19#discussion_r155180136"},"pull_request":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19"}},"in_reply_to_id":155117521},"pull_request":{"url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19","id":156574908,"html_url":"https://github.com/wurstscript/WurstStdlib2/pull/19","diff_url":"https://github.com/wurstscript/WurstStdlib2/pull/19.diff","patch_url":"https://github.com/wurstscript/WurstStdlib2/pull/19.patch","issue_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues/19","number":19,"state":"open","locked":false,"title":"Introduce new Syncing libraries","user":{"login":"SamuelMoriarty","id":3159552,"avatar_url":"https://avatars0.githubusercontent.com/u/3159552?v=4","gravatar_id":"","url":"https://api.github.com/users/SamuelMoriarty","html_url":"https://github.com/SamuelMoriarty","followers_url":"https://api.github.com/users/SamuelMoriarty/followers","following_url":"https://api.github.com/users/SamuelMoriarty/following{/other_user}","gists_url":"https://api.github.com/users/SamuelMoriarty/gists{/gist_id}","starred_url":"https://api.github.com/users/SamuelMoriarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamuelMoriarty/subscriptions","organizations_url":"https://api.github.com/users/SamuelMoriarty/orgs","repos_url":"https://api.github.com/users/SamuelMoriarty/repos","events_url":"https://api.github.com/users/SamuelMoriarty/events{/privacy}","received_events_url":"https://api.github.com/users/SamuelMoriarty/received_events","type":"User","site_admin":false},"body":"Each library comes with an extensive doc detailing the principles behind the library, the standard usage scenario as seen by the end user, and in the case of Network, an implementation overview to help you get oriented.\r\n\r\nThere are also a few minor changes in the other packages that I added during the development of this, that I thought deserved to be in the stdlib.","created_at":"2017-12-05T21:10:00Z","updated_at":"2017-12-06T09:15:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc3c9fb9ff40b842b6bf696a5b51d8079a7d31bb","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19/commits","review_comments_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19/comments","review_comment_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues/19/comments","statuses_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/statuses/938205f1adaa3adab361dcd137a119f60377899f","head":{"label":"SamuelMoriarty:master","ref":"master","sha":"938205f1adaa3adab361dcd137a119f60377899f","user":{"login":"SamuelMoriarty","id":3159552,"avatar_url":"https://avatars0.githubusercontent.com/u/3159552?v=4","gravatar_id":"","url":"https://api.github.com/users/SamuelMoriarty","html_url":"https://github.com/SamuelMoriarty","followers_url":"https://api.github.com/users/SamuelMoriarty/followers","following_url":"https://api.github.com/users/SamuelMoriarty/following{/other_user}","gists_url":"https://api.github.com/users/SamuelMoriarty/gists{/gist_id}","starred_url":"https://api.github.com/users/SamuelMoriarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamuelMoriarty/subscriptions","organizations_url":"https://api.github.com/users/SamuelMoriarty/orgs","repos_url":"https://api.github.com/users/SamuelMoriarty/repos","events_url":"https://api.github.com/users/SamuelMoriarty/events{/privacy}","received_events_url":"https://api.github.com/users/SamuelMoriarty/received_events","type":"User","site_admin":false},"repo":{"id":112357337,"name":"WurstStdlib2","full_name":"SamuelMoriarty/WurstStdlib2","owner":{"login":"SamuelMoriarty","id":3159552,"avatar_url":"https://avatars0.githubusercontent.com/u/3159552?v=4","gravatar_id":"","url":"https://api.github.com/users/SamuelMoriarty","html_url":"https://github.com/SamuelMoriarty","followers_url":"https://api.github.com/users/SamuelMoriarty/followers","following_url":"https://api.github.com/users/SamuelMoriarty/following{/other_user}","gists_url":"https://api.github.com/users/SamuelMoriarty/gists{/gist_id}","starred_url":"https://api.github.com/users/SamuelMoriarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamuelMoriarty/subscriptions","organizations_url":"https://api.github.com/users/SamuelMoriarty/orgs","repos_url":"https://api.github.com/users/SamuelMoriarty/repos","events_url":"https://api.github.com/users/SamuelMoriarty/events{/privacy}","received_events_url":"https://api.github.com/users/SamuelMoriarty/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SamuelMoriarty/WurstStdlib2","description":"WurstScript Standard Library Version 2","fork":true,"url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2","forks_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/forks","keys_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/teams","hooks_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/hooks","issue_events_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/issues/events{/number}","events_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/events","assignees_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/assignees{/user}","branches_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/branches{/branch}","tags_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/tags","blobs_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/git/refs{/sha}","trees_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/statuses/{sha}","languages_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/languages","stargazers_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/stargazers","contributors_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/contributors","subscribers_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/subscribers","subscription_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/subscription","commits_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/commits{/sha}","git_commits_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/git/commits{/sha}","comments_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/comments{/number}","issue_comment_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/issues/comments{/number}","contents_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/contents/{+path}","compare_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/merges","archive_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/downloads","issues_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/issues{/number}","pulls_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/pulls{/number}","milestones_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/milestones{/number}","notifications_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/labels{/name}","releases_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/releases{/id}","deployments_url":"https://api.github.com/repos/SamuelMoriarty/WurstStdlib2/deployments","created_at":"2017-11-28T16:03:58Z","updated_at":"2017-11-14T22:04:10Z","pushed_at":"2017-12-05T21:04:50Z","git_url":"git://github.com/SamuelMoriarty/WurstStdlib2.git","ssh_url":"git@github.com:SamuelMoriarty/WurstStdlib2.git","clone_url":"https://github.com/SamuelMoriarty/WurstStdlib2.git","svn_url":"https://github.com/SamuelMoriarty/WurstStdlib2","homepage":"","size":512,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wurstscript:master","ref":"master","sha":"494182dbe7cc0768a3f6f65e790bbb427b7df849","user":{"login":"wurstscript","id":30814797,"avatar_url":"https://avatars3.githubusercontent.com/u/30814797?v=4","gravatar_id":"","url":"https://api.github.com/users/wurstscript","html_url":"https://github.com/wurstscript","followers_url":"https://api.github.com/users/wurstscript/followers","following_url":"https://api.github.com/users/wurstscript/following{/other_user}","gists_url":"https://api.github.com/users/wurstscript/gists{/gist_id}","starred_url":"https://api.github.com/users/wurstscript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wurstscript/subscriptions","organizations_url":"https://api.github.com/users/wurstscript/orgs","repos_url":"https://api.github.com/users/wurstscript/repos","events_url":"https://api.github.com/users/wurstscript/events{/privacy}","received_events_url":"https://api.github.com/users/wurstscript/received_events","type":"Organization","site_admin":false},"repo":{"id":55271025,"name":"WurstStdlib2","full_name":"wurstscript/WurstStdlib2","owner":{"login":"wurstscript","id":30814797,"avatar_url":"https://avatars3.githubusercontent.com/u/30814797?v=4","gravatar_id":"","url":"https://api.github.com/users/wurstscript","html_url":"https://github.com/wurstscript","followers_url":"https://api.github.com/users/wurstscript/followers","following_url":"https://api.github.com/users/wurstscript/following{/other_user}","gists_url":"https://api.github.com/users/wurstscript/gists{/gist_id}","starred_url":"https://api.github.com/users/wurstscript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wurstscript/subscriptions","organizations_url":"https://api.github.com/users/wurstscript/orgs","repos_url":"https://api.github.com/users/wurstscript/repos","events_url":"https://api.github.com/users/wurstscript/events{/privacy}","received_events_url":"https://api.github.com/users/wurstscript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wurstscript/WurstStdlib2","description":"WurstScript Standard Library Version 2","fork":false,"url":"https://api.github.com/repos/wurstscript/WurstStdlib2","forks_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/forks","keys_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/teams","hooks_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/hooks","issue_events_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues/events{/number}","events_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/events","assignees_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/assignees{/user}","branches_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/branches{/branch}","tags_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/tags","blobs_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/git/refs{/sha}","trees_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/statuses/{sha}","languages_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/languages","stargazers_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/stargazers","contributors_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/contributors","subscribers_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/subscribers","subscription_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/subscription","commits_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/commits{/sha}","git_commits_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/git/commits{/sha}","comments_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/comments{/number}","issue_comment_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues/comments{/number}","contents_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/contents/{+path}","compare_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/merges","archive_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/downloads","issues_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues{/number}","pulls_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls{/number}","milestones_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/milestones{/number}","notifications_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/labels{/name}","releases_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/releases{/id}","deployments_url":"https://api.github.com/repos/wurstscript/WurstStdlib2/deployments","created_at":"2016-04-02T00:54:25Z","updated_at":"2017-12-05T21:02:29Z","pushed_at":"2017-12-06T01:29:59Z","git_url":"git://github.com/wurstscript/WurstStdlib2.git","ssh_url":"git@github.com:wurstscript/WurstStdlib2.git","clone_url":"https://github.com/wurstscript/WurstStdlib2.git","svn_url":"https://github.com/wurstscript/WurstStdlib2","homepage":"","size":502,"stargazers_count":7,"watchers_count":7,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":5,"open_issues":2,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19"},"html":{"href":"https://github.com/wurstscript/WurstStdlib2/pull/19"},"issue":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues/19"},"comments":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/issues/19/comments"},"review_comments":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19/comments"},"review_comment":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/pulls/19/commits"},"statuses":{"href":"https://api.github.com/repos/wurstscript/WurstStdlib2/statuses/938205f1adaa3adab361dcd137a119f60377899f"}},"author_association":"NONE"}}
{"actor":{"display_login":"SamuelMoriarty"}}