이거 어케 만들었을까요? HTML 채팅인데 > 자유게시판

자유게시판

이거 어케 만들었을까요? HTML 채팅인데 정보

이거 어케 만들었을까요? HTML 채팅인데

본문

COMET 같기도 하고

XE 용 위젯은 있던데, 그누용 채팅은 없나봐요.

소스 구하고 싶네요. ~ 만드실수 있는분 ?

추천
0
  • 복사

댓글 5개

var ohcsversion = "v1.2 beta";
var sessid = null;
var mynick = null;
var state = 0;
var userlist = new Array();
var successcount = 0;
var sctimer = null;
var ohcsMenubindings = {
    ban: function (a) {
        ohcsSendCommand("/ban " + $(a).attr("nick"))
    },
    kick: function (a) {
        ohcsSendCommand("/kick " + $(a).attr("nick"))
    },
    query: function (a) {
        $("#msgtext").val("/msg " + $(a).attr("nick") + " ");
        $("#msgtext").focus()
    },
    ip: function (a) {
        ohcsSendCommand("/ip " + $(a).attr("nick"))
    }
};

function ohcsShowMenu(b, c) {
    var a = $(b.target);
    if (a.attr("ip") == "none") {
        $("#ban,#kick,#ip", c).remove()
    }
    return c
}
$.contextMenu.defaults({
    menuStyle: {
        "font-size": "9pt"
    }
});

function scrollTimer() {
    var a = document.getElementById("chat");
    a.scrollTop = a.scrollHeight + 100;
    a.onscroll = function () {
        this.onscroll = null;
        this.scrollTop = this.scrollHeight + 100
    };
    sctimer = null
}
function adjustScroll() {
    if (state == 2) {
        return
    }
    var a = document.getElementById("chat");
    if (a.scrollTop + a.clientHeight + 150 >= a.scrollHeight || sctimer != null) {
        if ($.browser.msie) {
            clearTimeout(sctimer);
            sctimer = setTimeout("scrollTimer()", 100)
        } else {
            scrollTimer()
        }
    }
}
function addmsg(a, b) {
    $("#chat").append("<div class='message_normal message_" + a + "'>" + b + "</div>");
    adjustScroll()
}
function joinidx(b, a, c) {
    var d = "";
    for (i = a; i < b.length; i++) {
        d += (i != a ? c : "") + b[i]
    }
    return d
}
function ohcsDisconnect() {
    state = 0;
    successcount = 0;
    $("#mynick").attr("disabled", true);
    $("#msgtext").attr("disabled", true);
    $("#sendbt").attr("disabled", true);
    $("#userlist").children().each(function () {
        $(this).remove()
    });
    userlist = new Array()
}
function numtostr(a) {
    if (a < 10) {
        return "0" + a
    }
    return a
}
function ohcsUserinfoHoverIn(c) {
    var b = $(c.target);
    var a = new Date(b.attr("time") * 1000);
    $("#userinfo").html("<strong>" + b.attr("nick") + "</strong><br />시간 : " + numtostr(a.getFullYear()) + "." + numtostr(a.getMonth() + 1) + "." + numtostr(a.getDate()) + " " + numtostr(a.getHours()) + ":" + numtostr(a.getMinutes()) + ":" + numtostr(a.getSeconds()) + (b.attr("ip") == "none" ? "" : "<br />IP : " + b.attr("ip")));
    $("#userinfo2").html($("#userinfo").html());
    $("#userinfo").width($("#userinfo2").width());
    $("#userinfo").height($("#userinfo2").height());
    $("#userinfo").show();
    ohcsUserinfoMove(c)
}
function ohcsUserinfoHoverOut(a) {
    $("#userinfo").hide();
    $("#userinfo").css({
        top: 0,
        left: 0
    })
}
function ohcsUserinfoMove(c) {
    c.pageY += 4;
    var a = jQuery(window).width() - 2;
    var b = jQuery(window).height() - 4;
    if (c.pageX + $("#userinfo").width() >= a) {
        c.pageX = a - $("#userinfo").width() - 13
    }
    if (c.pageY + $("#userinfo").height() >= b) {
        c.pageY = b - $("#userinfo").height() - 13
    }
    $("#userinfo").css({
        top: c.pageY,
        left: c.pageX
    })
}
function ohcsData(c) {
    if (c.state != 200) {
        addmsg("error", "서버와 연결이 끊어졌습니다. (" + c.state + ") " + c.message);
        ohcsDisconnect();
        return
    }
    successcount = 0;
    if (state == 1) {
        state = 2;
        $("#mynick").attr("disabled", false);
        $("#msgtext").attr("disabled", false);
        $("#sendbt").attr("disabled", false);
        addmsg("info", "접속되었습니다.")
    }
    if (state != 2 && state != 3) {
        return
    }
    for (var b in c.messages) {
        var a;
        a = c.messages[b].message.split(" ");
        if (a[0] == "SETSESSID") {
            sessid = a[1];
            deleteCookie("sessid");
            setCookie("sessid", sessid, 0)
        } else {
            if (a[0] == "SETNICK") {
                mynick = a[1];
                deleteCookie("nick");
                setCookie("nick", mynick, 7);
                $("#mynick").val(mynick)
            } else {
                if (a[0] == "LOAD") {
                    state = 3;
                    scrollTimer()
                } else {
                    if (a[0] == "TEXT") {
                        addmsg("text", joinidx(a, 1, " "))
                    } else {
                        if (a[0] == "LOCKNICK") {
                            $("#mynick").attr("disabled", true)
                        } else {
                            if (a[0] == "UNLOCKNICK") {
                                $("#mynick").attr("disabled", false)
                            } else {
                                if (a[0] == "LOCKTEXT") {
                                    $("#msgtext").attr("disabled", true)
                                } else {
                                    if (a[0] == "UNLOCKTEXT") {
                                        $("#msgtext").attr("disabled", false)
                                    } else {
                                        if (a[0] == "MOVE") {
                                            location.href = joinidx(a, 1, " ")
                                        } else {
                                            if (a[0] == "ANN") {
                                                text = joinidx(a, 1, " ");
                                                addmsg("text", '<div class="message_nickname_oper2">-서버 공지사항-&nbsp;</div><div class="message_talkmsg">' + text + "</div>")
                                            } else {
                                                if (a[0] == "TALK" || a[0] == "TALK2") {
                                                    text = joinidx(a, 5, " ");
                                                    if (a[0] == "TALK") {
                                                        text = text.replace(/&/g, "&amp;");
                                                        text = text.replace(/</g, "&lt;");
                                                        text = text.replace(/>/g, "&gt;");
                                                        text = text.replace(/"/g, "&quot;")
                                                    }
                                                    if (a[4] == "oper") {
                                                        a[4] = "#000cff";
                                                        text = "<strong>" + text + "</strong>"
                                                    }
                                                    var d;
                                                    d = $("<div class='message_normal message_text'></div>");
                                                    $('<div nick="' + a[3] + '" style="color:' + a[4] + ';" class="message_nickname" time="' + a[1] + '" ip="' + a[2] + '">' + a[3] + ":&nbsp;</div>").hover(ohcsUserinfoHoverIn, ohcsUserinfoHoverOut).mousemove(ohcsUserinfoMove).contextMenu("userMenu", {
                                                        bindings: ohcsMenubindings,
                                                        onShowMenu: ohcsShowMenu
                                                    }).appendTo(d);
                                                    $('<div class="message_talkmsg">' + text + "</div>").appendTo(d);
                                                    $("#chat").append(d);
                                                    adjustScroll()
                                                } else {
                                                    if (a[0] == "SHOWCHANGENICK") {
                                                        addmsg("nick", '대화명 변경 <div class="message_nickname">' + a[1] + '</div> -&gt; <div class="message_nickname">' + a[2] + "</div>")
                                                    } else {
                                                        if (a[0] == "ADDUSER") {
                                                            $("<li class='userlist_li' nick='" + a[3] + "' time='" + a[1] + "' ip='" + a[2] + "'>" + a[3] + "</li>").hover(ohcsUserinfoHoverIn, ohcsUserinfoHoverOut).mousemove(ohcsUserinfoMove).contextMenu("userMenu", {
                                                                bindings: ohcsMenubindings,
                                                                onShowMenu: ohcsShowMenu
                                                            }).appendTo("#userlist");
                                                            userlist[a[1]] = "user"
                                                        } else {
                                                            if (a[0] == "SETOPER") {
                                                                userlist[a[1]] = "oper";
                                                                $("#userlist").children().each(function () {
                                                                    if ($(this).attr("nick") == a[1]) {
                                                                        $(this).html("*" + a[1])
                                                                    }
                                                                })
                                                            } else {
                                                                if (a[0] == "DELUSER") {
                                                                    $("#userlist").children().each(function () {
                                                                        if ($(this).attr("nick") == a[1]) {
                                                                            $(this).remove()
                                                                        }
                                                                    });
                                                                    delete userlist[a[1]]
                                                                } else {
                                                                    if (a[0] == "CHANGENICK") {
                                                                        $("#userlist").children().each(function () {
                                                                            if ($(this).attr("nick") == a[1]) {
                                                                                $(this).attr("nick", a[2]);
                                                                                if (userlist[a[1]] == "oper") {
                                                                                    $(this).html("*" + a[2])
                                                                                } else {
                                                                                    $(this).html(a[2])
                                                                                }
                                                                            }
                                                                        });
                                                                        userlist[a[2]] = userlist[a[1]];
                                                                        delete userlist[a[1]]
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    ohcsPing()
}
function ohcsError(a, c, b) {
    if (c == "timeout") {
        ohcsPing();
        return
    }
    successcount++;
    if (successcount == 0) {
        addmsg("error", "통신오류가 발생했습니다. (reason:" + c + ")")
    }
    if (successcount < 5) {
        ohcsPing();
        return
    }
    ohcsDisconnect()
}
function ohcsPing() {
    $.ajax({
        type: "POST",
        url: "/ohcs",
        async: true,
        data: {
            mode: "run",
            sessid: sessid
        },
        cache: false,
        timeout: 55000,
        success: ohcsData,
        error: ohcsError
    })
}
function ohcsNick() {
    if (state != 3) {
        return
    }
    if ($("#mynick").val() != mynick) {
        if ($("#mynick").val()) {
            $.ajax({
                type: "POST",
                url: "/ohcs",
                async: true,
                timeout: 5000,
                data: {
                    mode: "nick",
                    sessid: sessid,
                    text: $("#mynick").val()
                },
                cache: false
            })
        }
        $("#mynick").val(mynick);
        $("#msgtext").focus()
    }
}
function ohcsSendCommand(a) {
    $.ajax({
        type: "POST",
        url: "/ohcs",
        async: true,
        timeout: 5000,
        data: {
            mode: "text",
            sessid: sessid,
            text: a
        },
        cache: false
    })
}
function ohcsSend() {
    if (state != 3) {
        return
    }
    text = $("#msgtext").val();
    if (text) {
        if (text == "/debug") {}
        ohcsSendCommand(text);
        $("#msgtext").val("")
    }
    $("#msgtext").focus()
}
function ohcsInit(a, b, d) {
    var c;
    if (state != 0) {
        return
    }
    state = 1;
    successcount = 0;
    c = getCookie("sessid");
    if (!c) {
        c = ""
    }
    if (!a && !b && !d) {
        a = getCookie("nick");
        if (!a) {
            a = ""
        }
    }
    addmsg("system", "서버에 접속중입니다.");
    $.ajax({
        type: "POST",
        url: "/ohcs",
        async: true,
        data: {
            mode: "init",
            sessid: c,
            nick: a,
            text: b,
            time: d
        },
        cache: false,
        timeout: 5000,
        success: ohcsData,
        error: ohcsError
    })
}
$(document).ready(function () {
    $("#msgtext").keydown(function (a) {
        if (a.keyCode == "13") {
            ohcsSend()
        }
    });
    $("#mynick").keydown(function (a) {
        if (a.keyCode == "13") {
            ohcsNick()
        }
    });
    $("#mynick").focusin(function (a) {
        ohcsResizeNick()
    });
    $("#mynick").focusout(function (a) {
        ohcsResize()
    });
    if ($.browser.msie && parseInt($.browser.version, 10) == 8) {
        document.body.onresize = ohcsResize
    } else {
        $(window).resize(ohcsResize)
    }
    ohcsResize();
    addmsg("system", '<a href="http://ohcs.uu.gl" target="_blank">OHCS</a> ' + ohcsversion);
    ohcsDisconnect();
    $(document).bind("contextmenu", function (a) {
        return false
    });
    setTimeout("ohcsStart()", 10)
});

이게 주요 코드인듯..
그누용은 그냥 소스 추가하면 될텐데

모그님한테 물어보시는게 더 빠를 것 같네요.

문의는 IRC 채팅방에서 하시면 될 것 같습니다.
© SIRSOFT
현재 페이지 제일 처음으로