Skip to content

Network function exposed to scripts #1408

Closed
@konsumer

Description

@konsumer

I think it'd be really cool to have any sort of networking in TIC-80, especially if it also worked in wasm.

My usecase is that I want to use TIC-80 games as a frontend for stuff that can only be done on the backend. I think it might be useful for others for making multiplayer games, too, maybe behind a build-option flag.

It makes sense to me that it might be websockets, as it should work on wasm, with a little work. Even basic HTTP would be workable for my situation.

I am not great with C, but I'm happy to try to help. I did a little research and found this. I imagine in the lua interface it would look something like this:

function on_socket_open(address)
  print("socket opened")
  print(address)
end

function on_socket_close(address)
  print("socket closed")
  print(address)
end

function on_socket_message(address, msg)
  print("message")
  print(address)
  print(msg)
end

socket_listen(on_socket_message, on_socket_open, on_socket_close)

So the only thing that would need to be exposed to lua is socket_listen.

To get an address for a callback, it looks like this:

void onopen(int fd)
{
    char *cli;
    cli = ws_getaddress(fd);
    printf("Connection opened, client: %d | addr: %s\n", fd, cli);
    free(cli);
  // call lua function here with cli
}

Is this something you'd be interested in? Would you be willing to help me set it up, as I am very slow with C?

Activity

konsumer

konsumer commented on Apr 10, 2021

@konsumer
Author

After I typed this I realized I probably have it backwards, like it would make more sense to just put the client in TIC-80. Like I said, even a plain HTTP client would work (I see you are using curl elsewhere) as I could make my little service respond to requests, but I like the streaming nature of websockets, and it might make more sense for multiuser games.

nesbox

nesbox commented on Apr 12, 2021

@nesbox
Owner

Hi, this is a very disputable topic and we already decided to no add sockets to the API.
Only remote playing is allowed at the moment #457 and, maybe something like shared memory in the future.
Thank you and sorry :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @konsumer@nesbox

      Issue actions

        Network function exposed to scripts ยท Issue #1408 ยท nesbox/TIC-80