So i tryed out javascript and made a simple chatroom with 000webhost.com but i cant seem to figure out how to add features like promoting people as admin or the ability to kick,mute or ban people form the chat. Sorry if this question is giving you a headache but thanks for those who help
1 Answers
First, JavaScript alone isn't going to be enough -- you'll need a server-side language, like Ruby or PHP, for chat-users to talk to the server (and the server to deliver messages to different chatters).
Ultimately, you're going to end up giving each chatter a unique ID. A username, or an ID number. Where you store it doesn't really change how this operates... ...you can put users in a database, or in a text file, or have them connected to a different always-on program that the server talks to.
Then in order to kick people, just log them off. The next time they connect to the server, send a message back to their browser that they're not logged in (or aren't connected to that room).
To ban people, add them to a list of users you check for, where if the ID matches, they don't get any data (or get a "banned" message, instead).
How you accomplish this stuff is 100% up to you, but you need to start with a server-side language, a host that supports server-side languages, and some serious thinking about how you're going to structure everything.

- 26,167
- 5
- 41
- 49
-
Thanks for the help but in general terms can u be more descriptive as mean sever-sided? Im going to of course use php to but im not sure how to implement these – Ponder Sep 19 '12 at 21:49
-
@Ponder: Google and Wikipedia are your friends before StackOverflow. http://en.wikipedia.org/wiki/Server-side, http://en.wikipedia.org/wiki/Client-side. Nobody is going to give you a solution for your problem because it's not a problem, you're asking people to code for you, try it on your own first and if you fail come back here, post some code and more people will help – elclanrs Sep 19 '12 at 21:52
-
Create a session for each connected person. Give each person a unique ID when they connect (or write a login-form). Add the person to the list of active people in the chatroom. Write a PHP script that takes a "since" value, and the user-id. Have JS call that PHP script every 10s or 30s or whenever, and have PHP return all of the messages they haven't seen yet (after "since"). Have a PHP script that accepts userID, and message. In PHP, give that message an ID and add it to the stack. To ban somebody, block their ID from sending or receiving messages. Add in ***all kinds of security***. – Norguard Sep 19 '12 at 21:59
-
Thank you Norguard VERY helpful – Ponder Sep 19 '12 at 22:02
-
Just know that what I've given you is a ***horrible*** implementation for anything that's released into the public, as live code that you want people to use. You should also learn how to structure that code, either into libraries, or into a framework. Hopefully, into something which is object-oriented, or something which is entity-oriented (component/service-based, rather than object/method-based). You also need to learn about sanitization, when to use GET and POST, and learn how people can abuse your code to destroy your program, or to inject things onto other people's pages with your app. – Norguard Sep 19 '12 at 22:07