Android Open Source - steamchat Friend 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.steam2.handler;
// www . ja  v  a 2s.  c o m
import android.content.ContentValues;
import android.net.Uri;

import com.kevelbreh.steamchat.SteamChat;
import com.kevelbreh.steamchat.provider.SteamProvider;
import com.kevelbreh.steamchat.provider.SteamProvider.Nickname;
import com.kevelbreh.steamchat.provider.SteamProvider.Persona;
import com.kevelbreh.steamchat.provider.SteamProvider.User;
import com.kevelbreh.steamchat.provider.SteamProviderUtils;
import com.kevelbreh.steamchat.steam.language.Language;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientFriendsList;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientPlayerNicknameList;
import com.kevelbreh.steamchat.steam.proto.SteamMessagesClientServerProto.CMsgClientPersonaState;
import com.kevelbreh.steamchat.steam2.SteamEventBus;
import com.kevelbreh.steamchat.steam2.SteamService;
import com.kevelbreh.steamchat.steam2.packet.ProtoPacket;

import java.io.IOException;


public class FriendHandler {

    @SteamEventBus.SteamEvent(event = Language.Message.CLIENT_PERSONA_STATE)
    public static void onClientPersonaState(SteamService service, final byte[] data) throws IOException {
        ProtoPacket<CMsgClientPersonaState.Builder> packet = new ProtoPacket<CMsgClientPersonaState.Builder>(CMsgClientPersonaState.class);
        packet.setData(data);
        packet.deserialize();

        for (CMsgClientPersonaState.Friend friend : packet.getBody().getFriendsList()) {
            ContentValues values = new ContentValues(15);
            values.put(Persona.AVATAR_HASH, friend.getAvatarHash().toByteArray()); // blob
            values.put(Persona.CLAN_RANK, friend.getClanRank()); // int
            values.put(Persona.CLAN_TAG, friend.getClanTag()); // str
            values.put(Persona.FACEBOOK_ID, friend.getFacebookId()); // long
            values.put(Persona.GAME_ID, friend.getGameid()); // long
            values.put(Persona.GAME_NAME, friend.getGameName()); // str
            values.put(Persona.GAME_PLAYED_APP_ID, friend.getGamePlayedAppId()); // int
            values.put(Persona.GAME_SERVER_IP, friend.getGameServerIp());// int
            values.put(Persona.GAME_SERVER_PORT, friend.getGameServerPort()); // int
            values.put(Persona.LAST_LOG_OFF, friend.getLastLogoff()); // int
            values.put(Persona.LAST_LOG_ON, friend.getLastLogon()); //int
            values.put(Persona.PERSONA_SET_BY_USER, friend.getPersonaSetByUser()); // bool
            values.put(Persona.PERSONA_STATE, friend.getPersonaState()); // int
            values.put(Persona.PERSONA_STATE_FLAGS, friend.getPersonaStateFlags()); // int
            values.put(Persona.PLAYER_NAME, friend.getPlayerName()); //str

            final Uri userUri = SteamProviderUtils.getUserFromSteamId(service, friend.getFriendid());

            // Continue if we didn't manage to find the user id.
            if (userUri == null) {
                SteamChat.debug("Couldn't find user for " + friend.getFriendid()
                        + "(" + friend.getPlayerName() +")");
                continue;
            }

            final Uri personaUri = SteamProvider.User.PERSONA.getUri(userUri);
            if (!SteamProviderUtils.isExisting(service, personaUri, null, null)) {
                // There isn't a persona for this user so add one.
                service.getContentResolver().insert(personaUri, values);
            } else {
                // There is already an existing persona so update the entry.  We can overwrite the
                // all the data because we have no idea what changed (and adding checks is tedious).
                service.getContentResolver().update(personaUri, values, null, null);
            }
        }
    }

    @SteamEventBus.SteamEvent(event = Language.Message.CLIENT_FRIENDS_LIST)
    public static void onClientFriendsList(SteamService service, final byte[] data)  throws IOException {
        ProtoPacket<CMsgClientFriendsList.Builder> packet = new ProtoPacket<CMsgClientFriendsList.Builder>(CMsgClientFriendsList.class);
        packet.setData(data);
        packet.deserialize();

        String selection = SteamProvider.User.STEAM_ID + "=?";

        for (CMsgClientFriendsList.Friend friend : packet.getBody().getFriendsList()) {
            ContentValues values = new ContentValues(2);
            values.put(User.STEAM_ID, friend.getUlfriendid());
            values.put(User.RELATIONSHIP, friend.getEfriendrelationship());

            String[] args = new String[] { String.valueOf(friend.getUlfriendid()) };
            if (!SteamProviderUtils.isExisting(service, User.CONTENT_URI, selection, args)) {
                // This steam user does not yet exist so add a new entry.
                service.getContentResolver().insert(User.CONTENT_URI, values);
            } else {
                // This team user already exists so update the entry.  We can overwrite the
                // steam_id because it won't be changing.
                service.getContentResolver().update(User.CONTENT_URI, values, selection, args);
            }
        }
    }

    @SteamEventBus.SteamEvent(event = Language.Message.CLIENT_FRIENDS_GROUPS_LIST)
    public static void onClientFriendsGroupsList(SteamService service, final byte[] data)  throws IOException {

    }

    @SteamEventBus.SteamEvent(event = Language.Message.CLIENT_PLAYER_NICKNAME_LIST)
    public static void onClientPlayerNicknameList(SteamService service, final byte[] data) throws IOException {
        final ProtoPacket<CMsgClientPlayerNicknameList.Builder> packet = new ProtoPacket<CMsgClientPlayerNicknameList.Builder>(CMsgClientPlayerNicknameList.class);
        packet.setData(data);
        packet.deserialize();

        for (CMsgClientPlayerNicknameList.PlayerNickname nickname : packet.getBody().getNicknamesList()) {
            ContentValues values = new ContentValues(1);
            values.put(Nickname.NICKNAME, nickname.getNickname());

            // Continue if we didn't manage to find the user id.
            final Uri userUri = SteamProviderUtils.getUserFromSteamId(service, nickname.getSteamid());
            if (userUri == null) {
                SteamChat.debug("Couldn't find user for " + nickname.getSteamid() + "(" + nickname.getNickname() + ")");
                continue;
            }

            final Uri nicknameUri = User.NICKNAME.getUri(userUri);
            if (!SteamProviderUtils.isExisting(service, nicknameUri, null, null)) {
                // There isn't a nickname for this user so add one.
                service.getContentResolver().insert(nicknameUri, values);
            } else {
                // There is already an existing nickname so update the entry.
                service.getContentResolver().update(nicknameUri, values, null, null);
            }
        }
    }
}




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