Android Open Source - steamchat Friends Handler






From Project

Back to project page steamchat.

License

The source code is released under:

Apache License

If you think the Android project steamchat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kevelbreh.steamchat.steam.handler;
/*from  w  w  w  .  j a va  2  s  .c o m*/
import com.kevelbreh.steamchat.SteamChat;
import com.kevelbreh.steamchat.provider.SteamProvider;
import com.kevelbreh.steamchat.steam.SteamClient;
import com.kevelbreh.steamchat.steam.SteamServiceHandler;
import com.kevelbreh.steamchat.steam.language.Language;
import com.kevelbreh.steamchat.steam.network.packet.Packet;
import com.kevelbreh.steamchat.steam.network.packet.ProtoPacket;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientFriendsList;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientPersonaState;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientPlayerNicknameList;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientChangeStatus;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientFriendMsgIncoming;
import com.kevelbreh.steamchat.steam.util.BinaryReader;

import java.io.IOException;

/**
 * This class is responsible for interfacing with client friends specific events.
 */
public class FriendsHandler extends AEventHandler implements IEventHandler {

    public FriendsHandler(SteamClient client) {
        super(client);
    }

    @Override
    public SteamServiceHandler getHandler() {
        return new SteamServiceHandler();
    }

    @Override
    public void onEventReceived(SteamClient client, int type, Packet packet) {
        try {
            switch (type) {
                case 768:
                    onClientAccountInfo(packet);
                    break;

                case Language.Message.CLIENT_LOGGED_OFF:
                    break;

                case 767:
                    onFriendsList(packet);
                    break;

                case 5553:
                    onGroupList(packet);
                    break;

                case 5587:
                    onNicknameList(packet);
                    break;

                case Language.Message.CLIENT_PERSONA_STATE:
                    onPersonaState(packet);
                    break;

                case Language.Message.CLIENT_FRIEND_MSG_INCOMING:
                    onFriendMessage(packet);
                    break;

                case Language.Message.CLIENT_FRIEND_MESSAGE_ECHO_TO_SENDER:
                    onEchoMessage(packet);
                    break;
            }
        }
        catch(final IOException e) {
            SteamChat.debug(this, e.toString());
       }
    }

    @Override
    public void onConnected(SteamClient client) {

    }

    @Override
    public void onDisconnected(SteamClient client) {

    }

    @Override
    public void onAuthenticated(SteamClient client) {

    }

    private void onEchoMessage(Packet packet) throws IOException {
        ProtoPacket<CMsgClientFriendMsgIncoming.Builder> incoming =
                new ProtoPacket<CMsgClientFriendMsgIncoming.Builder>(CMsgClientFriendMsgIncoming.class);
        incoming.deserialize(packet.getData());

        SteamProvider.Interaction.addEchoChatOutgoing(getSteamClient().getContext(), incoming.getBody());
    }

    private void onFriendMessage(Packet packet) throws IOException {
        ProtoPacket<CMsgClientFriendMsgIncoming.Builder> incoming =
                new ProtoPacket<CMsgClientFriendMsgIncoming.Builder>(CMsgClientFriendMsgIncoming.class);
        incoming.deserialize(packet.getData());

        SteamProvider.Interaction.addChatIncoming(getSteamClient().getContext(), incoming.getBody());
    }

    // todo: save persona name.
    private void onClientAccountInfo(Packet packet) throws IOException {
        ProtoPacket<CMsgClientChangeStatus.Builder> request =
                new ProtoPacket<CMsgClientChangeStatus.Builder>(CMsgClientChangeStatus.class);

        request.setMessageType(Language.Message.CLIENT_CHANGE_STATUS);
        request.getHeader().setClientSessionid(getSteamClient().getConnection().sessionid);
        request.getHeader().setSteamid(getSteamClient().getConnection().steamid);
        request.getHeader().setJobidTarget(BinaryReader.LongMaxValue);
        request.getHeader().setJobidSource(BinaryReader.LongMaxValue);

        request.getBody().setPersonaState(Language.PersonaState.ONLINE);
        request.getBody().setPlayerName("Kev");

        getSteamClient().send(request);
    }

    private void onFriendsList(Packet packet) throws IOException {
        ProtoPacket<CMsgClientFriendsList.Builder> p =
                new ProtoPacket<CMsgClientFriendsList.Builder>(CMsgClientFriendsList.class);
        p.deserialize(packet.getData());

        SteamProvider.User.addFriendsList(getSteamClient().getContext(), p.getBody().getFriendsList());

        /*ProtoPacket<CMsgClientRequestFriendData.Builder> request =
                new ProtoPacket<CMsgClientRequestFriendData.Builder>(CMsgClientRequestFriendData.class);

        for (CMsgClientFriendsList.Friend friend : p.getBody().getFriendsList()) {
            request.getBody().addFriends(friend.getUlfriendid());
        }

        request.setMessageType(Language.Message.CLIENT_REQUEST_FRIEND_DATA);
        request.getHeader().setClientSessionid(getSteamClient().getConnection().sessionid);
        request.getHeader().setSteamid(getSteamClient().getConnection().steamid);
        request.getHeader().setJobidTarget(BinaryReader.LongMaxValue);
        request.getHeader().setJobidSource(BinaryReader.LongMaxValue);

        request.getBody().setPersonaStateRequested(
                Language.ClientPersonaStateFlag.PLAYER_NAME |
                Language.ClientPersonaStateFlag.PRESENCE |
                Language.ClientPersonaStateFlag.SOURCE_ID |
                Language.ClientPersonaStateFlag.GAME_EXTRA_INFO |
                Language.ClientPersonaStateFlag.METADATA |
                Language.ClientPersonaStateFlag.STATUS |
                Language.ClientPersonaStateFlag.LAST_SEEN);

        getSteamClient().send(request);*/
    }

    private void onGroupList(Packet packet)  throws IOException {
        /*ProtoPacket<CMsgClientFriendsGroupsList.Builder> p =
                new ProtoPacket<CMsgClientFriendsGroupsList.Builder>(CMsgClientFriendsGroupsList.class);
        p.deserialize(packet.getData());

        List<CMsgClientFriendsGroupsList.FriendGroup> groups = p.getBody().getFriendGroupsList();
        for (CMsgClientFriendsGroupsList.FriendGroup group  : groups) {
            SteamChat.debug(this, "GROUP: " + group.getNGroupID() + " AS " + group.getStrGroupName());
        }*/
    }

    private void onNicknameList(Packet packet)  throws IOException {
        ProtoPacket<CMsgClientPlayerNicknameList.Builder> p =
                new ProtoPacket<CMsgClientPlayerNicknameList.Builder>(CMsgClientPlayerNicknameList.class);
        p.deserialize(packet.getData());

        SteamProvider.Nickname.addNicknameList(getSteamClient().getContext(), p.getBody().getNicknamesList());
    }

    private void onPersonaState(Packet packet) throws IOException {
        ProtoPacket<CMsgClientPersonaState.Builder> p =
                new ProtoPacket<CMsgClientPersonaState.Builder>(CMsgClientPersonaState.class);
        p.deserialize(packet.getData());

        SteamProvider.Persona.addPersonaList(getSteamClient().getContext(), p.getBody().getFriendsList());
    }
}




Java Source Code List

com.kevelbreh.steamchat.SteamChat.java
com.kevelbreh.steamchat.account.AuthenticatorService.java
com.kevelbreh.steamchat.account.Authenticator.java
com.kevelbreh.steamchat.account.SteamAccount.java
com.kevelbreh.steamchat.activity.AuthenticationActivity.java
com.kevelbreh.steamchat.activity.ConversationActivity.java
com.kevelbreh.steamchat.activity.FriendsActivity.java
com.kevelbreh.steamchat.activity.InteractionsActivity.java
com.kevelbreh.steamchat.activity.LauncherActivity.java
com.kevelbreh.steamchat.activity.SettingsActivity.java
com.kevelbreh.steamchat.fragment.ConversationFragment.java
com.kevelbreh.steamchat.fragment.FriendsFragment.java
com.kevelbreh.steamchat.fragment.InteractionsFragment.java
com.kevelbreh.steamchat.fragment.SettingsFragment.java
com.kevelbreh.steamchat.provider.SteamProviderUtils.java
com.kevelbreh.steamchat.provider.SteamProvider.java
com.kevelbreh.steamchat.provider.content.InteractionContentItem.java
com.kevelbreh.steamchat.provider.content.PersonaContentItem.java
com.kevelbreh.steamchat.provider.content.UserContentItem.java
com.kevelbreh.steamchat.steam2.SteamConnection.java
com.kevelbreh.steamchat.steam2.SteamEventBus.java
com.kevelbreh.steamchat.steam2.SteamService.java
com.kevelbreh.steamchat.steam2.handler.ConnectionHandler.java
com.kevelbreh.steamchat.steam2.handler.FriendHandler.java
com.kevelbreh.steamchat.steam2.handler.MessageHandler.java
com.kevelbreh.steamchat.steam2.handler.UserHandler.java
com.kevelbreh.steamchat.steam2.packet.Packet.java
com.kevelbreh.steamchat.steam2.packet.ProtoPacket.java
com.kevelbreh.steamchat.steam.SteamClient.java
com.kevelbreh.steamchat.steam.SteamID.java
com.kevelbreh.steamchat.steam.SteamServiceHandler.java
com.kevelbreh.steamchat.steam.SteamService.java
com.kevelbreh.steamchat.steam.handler2.ConnectionHandler.java
com.kevelbreh.steamchat.steam.handler2.FriendHandler.java
com.kevelbreh.steamchat.steam.handler2.Handler.java
com.kevelbreh.steamchat.steam.handler2.UserHandler.java
com.kevelbreh.steamchat.steam.handler.AEventHandler.java
com.kevelbreh.steamchat.steam.handler.AuthenticationHandler.java
com.kevelbreh.steamchat.steam.handler.FriendsHandler.java
com.kevelbreh.steamchat.steam.handler.IEventHandler.java
com.kevelbreh.steamchat.steam.handler.IHandler.java
com.kevelbreh.steamchat.steam.handler.MessageDebugHandler.java
com.kevelbreh.steamchat.steam.language.Language.java
com.kevelbreh.steamchat.steam.language.Message.java
com.kevelbreh.steamchat.steam.network.TCPConnection.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptRequest.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptResponse.java
com.kevelbreh.steamchat.steam.network.packet.ChannelEncryptResult.java
com.kevelbreh.steamchat.steam.network.packet.ClientLogOnResponse.java
com.kevelbreh.steamchat.steam.network.packet.ClientLogOn.java
com.kevelbreh.steamchat.steam.network.packet.HeartBeat.java
com.kevelbreh.steamchat.steam.network.packet.MultiPacket.java
com.kevelbreh.steamchat.steam.network.packet.Packet.java
com.kevelbreh.steamchat.steam.network.packet.ProtoPacket.java
com.kevelbreh.steamchat.steam.proto.DescriptorsProto.java
com.kevelbreh.steamchat.steam.proto.EncryptedAppTicketProto.java
com.kevelbreh.steamchat.steam.proto.SteamMessagesBaseProto.java
com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.java
com.kevelbreh.steamchat.steam.security.AsnKeyParser.java
com.kevelbreh.steamchat.steam.security.AsnParser.java
com.kevelbreh.steamchat.steam.security.BerDecodeException.java
com.kevelbreh.steamchat.steam.security.Cryptography.java
com.kevelbreh.steamchat.steam.security.NetEncryption.java
com.kevelbreh.steamchat.steam.security.PublicKey.java
com.kevelbreh.steamchat.steam.security.RSA.java
com.kevelbreh.steamchat.steam.util.BinaryReader.java
com.kevelbreh.steamchat.steam.util.BinaryWriter.java
com.kevelbreh.steamchat.steam.util.BitVector64.java
com.kevelbreh.steamchat.steam.util.JenkinsHash.java
com.kevelbreh.steamchat.util.AServiceActivity.java
com.kevelbreh.steamchat.util.Dump.java
com.kevelbreh.steamchat.util.MiscUtils.java
com.kevelbreh.steamchat.widget.adapter.ChatAdapter.java
com.kevelbreh.steamchat.widget.adapter.ConversationAdapter.java
com.kevelbreh.steamchat.widget.adapter.FriendAdapter.java
com.kevelbreh.steamchat.widget.view.AvatarView.java
com.kevelbreh.steamchat.widget.view.FriendInteractionsView.java