Skip to content

Commit

Permalink
some more shit
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Feb 15, 2024
1 parent 9560549 commit 0f5aed8
Show file tree
Hide file tree
Showing 12 changed files with 7,959 additions and 399 deletions.
60 changes: 60 additions & 0 deletions source/backend/Socket.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package backend;

#if sys
import sys.net.Host;
import sys.net.Socket as SysSocket;

@:keep
class Socket implements flixel.util.FlxDestroyUtil.IFlxDestroyable {
public var socket:SysSocket;

public function new(?socket:SysSocket) {
this.socket = socket;
if (this.socket == null)
this.socket = new SysSocket();
this.socket.setFastSend(true);
this.socket.setBlocking(false);
}

public function read():String {
try {
return this.socket.input.readUntil(('\n').charCodeAt(0)).replace("\\n", "\n");
} catch(e) trace('ERROR SOCKET READ - ${e}');
return null;
}

public function write(str:String):Bool {
try {
this.socket.output.writeString(str.replace("\n", "\\n"));
return true;
} catch(e) trace('ERROR SOCKET WRITE - ${e}');
return false;
}

public function host(host:Host, port:Int, nbConnections:Int = 1) {
socket.bind(host, port);
socket.listen(nbConnections);
socket.setFastSend(true);
}

public function hostAndWait(h:Host, port:Int) {
host(h, port);
return acceptConnection();
}

public function acceptConnection():Socket {
socket.setBlocking(true);
var accept = new Socket(socket.accept());
socket.setBlocking(false);
return accept;
}

public function connect(host:Host, port:Int) {
socket.connect(host, port);
}

public function destroy() {
if (socket != null) socket.close();
}
}
#end
154 changes: 0 additions & 154 deletions source/extraflixel/FlxSprite3D.hx

This file was deleted.

Loading

0 comments on commit 0f5aed8

Please sign in to comment.