Skip to content

Get Started with Spider

Gilbok Lee edited this page Nov 10, 2015 · 17 revisions

Get started with Spider

코드네임 Spider는 Hive5 SDK의 실시간(Realtime)기능 지원을 부르는 말입니다.

초기화(Initialize)

Hive5Client는 이미 초기화되어 있다고 가정합니다. Hive5Client 초기화는 여기를 참고하세요.

Hive5Spider spider = new Hive5Spider(Hive5Client.Instance);

서버접속

서버연결(Connect)

아래와 같이 호출하면 서버에 연결합니다.

spider.Connect(OnConnected);

콜백함수의 예는 아래와 같습니다.

private void OnConnected(bool success)
{
    // spider.SessionId 등에 유효한 값이 들어있을 것입니다.
}

서버접속끊기(Disconnect)

아래와 같이 호출하면 서버 접속을 끊습니다.

spider.Disconnect(OnDisconnect);

콜백함수의 예는 아래와 같습니다.

private void OnDisconnect(bool success)
{
}

물론 람다표현식으로 구현 가능합니다.

spider.Disconnect((success) =>
{
    // 접속종료됨
});

메세지

메세지 내용은 string타입의 key와 string타입의 value의 딕셔너리 타입으로 지원합니다.

메세지 전송

1. 공개메세지 전송(SendChannelMessage)

Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendChannelMessage");
spider.SendChannelMessage(contents, (success, publicationId) =>
{

});

2. 비공개메세지 전송(SendPrivateMessage)

Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendPrivateMessage");
spider.SendPrivateMessage(platformUserId, contents, (success, publicationId) =>
{
});

3. 공지메세지 전송(SendNoticeMessage)

Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendNoticeMessage");
spider.SendNoticeMessage(appSecret, contents, (success, publicationId) =>
{
});

4. 시스템메세지 전송(SendSystemMessage)

Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendSystemMessage");
spider.SendSystemMessage(contents, (success, publicationId) =>
{
});

메세지수신(EventMessageReceived)

게임의 라이프타임 중 1번만 이벤트핸들러를 설정해 주면 됩니다.

spider.MessageReceived+= (sender, topicKind, messageContents) =>
{
    switch(topicKind)
    {
        case TopicKind.Channel: // Channel 메세지
            {
                Debug.Log(messageContents["message"]);
            }
            break;
        case TopicKind.Private: // Private 메세지
            {
                Debug.Log(messageContents["message"]);
            }
            break;
        case TopicKind.Notice: // Notice 메세지
            {
                Debug.Log(messageContents["message"]);
            }
            break;
        case TopicKind.System: // System 메세지
            {
                Debug.Log(messageContents["message"]);
            }
            break;
    }
}

기능호출

채널 목록 가져오기(GetChannels)

아래와 같이 호출합니다.

spider.GetChannels(OnGetChannels);

콜백함수의 예는 아래와 같습니다.

private void OnGetChannels(bool success, CallResult result)
{
    GetChannelsResult castedResult = result as GetChannelsResult;
    // castedResult.Channels에 접근이 가능합니다.
}

플레이어 목록 가져오기(GetPlayers)

아래와 같이 호출합니다.

spider.GetPlayers(OnGetPlayers);

콜백함수의 예는 아래와 같습니다.

private void OnGetPlayers(bool success, CallResult result)
{
    GetPlayersResult castedResult = result as GetPlayersResult;
    // castedResult.PlatformUserIds에 접근이 가능합니다.
}

라이선스

Websocket-Sharp

스파이더에서 웹소켓에 인터페이스 하기 위해서 MIT License인 Websocket-Sharp을 사용하고 있습니다. Websocket-Sharp은 아래 링크를 통해 배포되고 있습니다. https://github.com/sta/websocket-sharp/

Clone this wiki locally