Imagine this: you load up a 4chan chat page, and you're connected to another user to chat one on one. Completely at random, with no traces of identity whatsoever. That's it. There could be a button to get a new person if you really don't like who you're talking to or you've seen them before, or you could just hit F5. In the true spirit of Anonymous, you could talk about anything in complete freedom.
I think that could be pretty awesome (and also pretty fail, but such is the way of all things chan), and it's an idea that I've had in the back of my mind for a while. I don't have the wherewithal to make it happen, however, so by /img/'s recommendation I'm here pitching it to /prog/ in the hope that someone will get inspired and make this happen. I'd really like to see it made real. I have to imagine that it would be very simple to make, although finding a good host and getting people to use it is another matter.
{ new_client, ClientSock }
->
% Spawn a new thread for this client, attempt to get name
spawn( server, client_get_name, [ ClientSock, self() ] ),
% Loop
responder( ClientList );
{ client_choose_name, { ClientSock, ClientName } }
->
% Make sure the name isn't taken.
case lists:keysearch( ClientName, 2, ClientList ) of
false
->
% Add the client into the list
NewClientList = [ { ClientSock, ClientName } | ClientList ],
% Send the join message to all users
send_to_all_clients(
NewClientList,
io_lib:format(
"~s has joined the chat.~n",
[ ClientName ]
)
),
% Set up the thread to listen for that client
spawn( server, client,
[ { ClientSock, ClientName }, self() ]
),
% Loop with new client list.
responder( NewClientList );
{ value, _ }
->
% Send them a message
gen_tcp:send( ClientSock,
io_lib:format(
"The name ~s is already taken.~n",
[ ClientName ]
)
),
% Request they choose another name
spawn( server, client_get_name, [ ClientSock, self() ] ),
% Loop with old client list.
responder( ClientList )
end;
% Already looped above.
{ client_message, Msg }
->
% Message is preformatted.
% Need to send the message to all clients.
send_to_all_clients( ClientList, Msg ),
% Loop
responder( ClientList );
{ client_closed, { ClientSock, ClientName } }
->
% Remove the entry from the list, if it exists.
NewClientList = lists:keydelete( ClientSock, 1, ClientList ),
% Send message to all clients about logoff.
send_to_all_clients(
NewClientList,
io_lib:format( "~s has left the chat.~n", [ ClientName ] )
),