How to pass custom data to GPaas server from ios?

0 votes

Hi,

I have deployed zip file on GPaas which contains logic to create virtual userand I have made changes in ChatServer app to create virtual user.  I am passing static room and zone while adding virtual user and it added in room successfully. But now I want to add virtual user in room and zone dynamically. Means from ios I want to pass room and zone and virtual user should be added to that particular room and zone only. Now I'm stuck at this point. How Can I pass custom data to GPaas server to add vitual user in given room and zone?

Code to create virtual user by making changes in ChatServer demo provided by appwarp s2.

1. ChatZoneAdaptor.java:

public void onAdminRoomAdded(IRoom room)
    {
        //System.out.println("Printing zone from adaptor > " + ChatServerAdaptor.zone);
        
        User user = (User) new VirtualUser("Bot_1", (Room) room, (Zone) ChatServerAdaptor.zone);
        room.addUser(user, true);
        System.out.println("added virtual user named : " + user.getName() + "  ... In room : " + room.getName());
        
        System.out.println("Room Created " + room.getName() + " with ID " + room.getId() );
        room.setAdaptor(new ChatRoomAdaptor());
        
        room.BroadcastChat(user.getName(), "Hey! I am Moving");
    }

2. ChatServerAdaptor.java:

public class ChatServerAdaptor extends BaseServerAdaptor{ 
public static IZone zone; 
 @Override public void onZoneCreated(IZone zone) { 
 this.zone = zone; 
 System.out.println("Zone Created By PS == " + this.zone.getName() + " with key " + zone.getAppKey()); 
 zone.setAdaptor(new ChatZoneAdaptor()); }
‚Äč}

 

asked Jan 19 in App42PaaS & BPaaS by contact (16 points)

1 Answer

+1 vote
 
Best answer

Hi Contact,

Greetings from ShepHertz!!!!

As Virtual User will be created inside a room w.r.to Zone it will be created. So it will be created inside RoomAdapter on server, in already created Zone and Room.  So there is way to achieve the same by passing the data from iOS client side.

But you can pass other data like name and other extra Data from Client side for virtual User Creation on server. To achieve this you can define a function at RoomAdapter and call the same by calling RoomRPC API from client side w.r.to room.

    public String createVirtualUser(String virtualUserName) {
        IUser user = (IUser) new VirtualUser(virtualUserName, (Room) gameRoom,
                (Zone) iZone);
        gameRoom.addUser(user, true);
        return "success";
    }

Let me know if it helps.

Thanks

Vishnu Garg

 

answered Jan 19 by Vishnu Garg (663 points)
selected Jan 19 by contact
Thanks Vishnu.Now I'm getting response(success) and method name using onRPCDone in iOS
Let me know if more queries are there.
Now I want to use roomId passing from ios in java. And want to add Virtual user in that room.

From iOS i'm passing roomId using invokeRoomRPCFunction like this:

 WarpClient *wrCl = [WarpClient getInstance];
    NSLog(@"_roomIDArray[indexPath.row] == %@",_roomIDArray[indexPath.row]);
    
    NSDate *dt = [NSDate date];
    NSDateFormatter *form = [[NSDateFormatter alloc]init];
    [form setDateFormat:@"ddmmyy_hhmmss"];
    
    [wrCl invokeRoomRPCFunction:@"createVirtualUser" RoomID:@"335824901" andArguments:[NSString stringWithFormat:@"Bot_%@",[form stringFromDate:dt]],nil];

How can I get room from roomid i'm passing from iOS and add uer in that room?

 IUser user = (IUser) new VirtualUser(virtualUserName, (Room) gameRoom,
                (Zone) iZone);
        gameRoom.addUser(user, true);
In this case you can create same function at Zone adapter and pass room Id as second parameter and on server you need to get All the rooms of zone and than get and validate the same and create Virtual User over there like :

 public String createVirtualUser(String virtualUserName,String roomId) {
         Collection<IRoom> rooms= izone.getRooms();
          Iterator roomsItr = rooms.iterator();
          
          while(roomsItr.hasNext()) {
              IRoom gameRoom = (IRoom) roomsItr.next();
             if(gameRoom.getId().equalsIgnoreCase(roomId)){
                 IUser user = (IUser) new VirtualUser(virtualUserName, (Room) gameRoom,
                         (Zone) izone);
                 gameRoom.addUser(user, true);
                 return "Success";
             }
          }
            return "Failed";
        }
Ok. Let me try this.
Yeah!! It's working. Thanks a lot!!
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
Migrate from Parse to ShepHertz App42
...