Player name on auto pick option for invitation - multiplayer

We have developed a multiplayer game using google play services.
When we send a request to the api for inviting friends to play, on clicking auto pick, the opponent's name does not show, instead the list shows any random name as in Player_1231,Player_3333 etc.
We need help regarding this issue. We need proper player names to play the game.Kindly check the screenshots attached.
Immediate help will be appreciated.

Please find the code below:
public void onRoomConnected(int statusCode, Room room) {
// TODO Auto-generated method stub
if (statusCode != mGamesClient.STATUS_PARTICIPANT_NOT_CONNECTED) {
// Toast.makeText(this, " is PARTICIPANT_CONNECTED.",
// Toast.LENGTH_SHORT).show();
roomId = room.getRoomId();
room_creator_id = room.getCreatorId();
// participantId = p.getParticipantId();
current_player_id = room.getParticipantId(mGamesClient
.getCurrentPlayerId());
Asset.self = Asset.username;
if (room_creator_id != null) {
if (room_creator_id.equals(current_player_id)) {
Server = true;
}
}
// Toast.makeText(this,
// " is PARTICIPANT_CONNECTED."+room_creator_id,
// Toast.LENGTH_SHORT).show();
par = null;
par = room.getParticipants();
for (Participant p : par) {
if (!p.getParticipantId().equals(current_player_id)) {
System.out.println(current_player_id
+ " After 1 connect " + p.getParticipantId());
participantId = p.getParticipantId();
Asset.opponent = p.getDisplayName();
break;
}
}
menu.initPage(GameConst.SELECTLEVEL_PAGE_ONLINE);
menu.Start_Selection_Timer();
}
// Toast.makeText(this, " is onRoomConnected.",
// Toast.LENGTH_SHORT).show();
}
PLAY ONLINE---------------
public void startQuickGame() {
// automatch criteria to invite 1 random automatch opponent.
// You can also specify more opponents (up to 3).
if (mGamesClient.isConnected()) {
Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);
// build the room config:
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.setAutoMatchCriteria(am);
RoomConfig roomConfig = roomConfigBuilder.build();
// create room:
mGamesClient.createRoom(roomConfig);
} else {
Toast.makeText(con, "Wait for connection or try after some time",
Toast.LENGTH_SHORT).show();
mGamesClient.connect();
}
// go to game screen
}

Related

Switch WiFi mode from AP to STA

I'm working on project with ESP32-S2-Saola-1M board in C/C++ via ESP-IDF framework. At the beginning I initialize a Wi-Fi in an AP mode and starts the HTTP WebServer to get WiFi data from user through browser. After the user saves his Wi-Fi data (SSID and Passwd) throught page, the
HTTP server should shut down and Wi-Fi switch from AP mode to STA mode - connect to user's Wi-Fi. I have problem with this part. I don't know how to solve this elegantly and in principle correctly. So can someone describe me any solutions or better ideas please?
I thought of using method with while cycle and POST handler. After the data comes from page via POST request, handler saves them and set some bool property (e.g. hasData in code below) to true and while cycle in method breaks/stops and other code in application can continue. Something like semaphore. Simply:
start Wi-Fi (AP mode)
start webserver
wait until user sends his Wi-Fi data
stop webserver
stop Wi-Fi AP mode -> switch to STA mode
next actions... (measure, send data out, deep sleep etc.)
Pseudo code:
bool hasData = false;
static esp_err_t postHandler(httpd_req_t *request)
{
.
. //saves data from POST request
.
hasData = true;
return ESP_OK;
}
void waitForUser(void)
{
while(hasData != true) {
//just wait
}
}
static const httpd_uri_t postData = {
.uri = "/connection",
.method = HTTP_POST,
.handler = postHandler,
.user_ctx = NULL
};
static httpd_handle_t start_webserver(void)
{
httpd_handle_t server = NULL;
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
if (httpd_start(&server, &config) == ESP_OK) {
httpd_register_uri_handler(server, &postData);
return server;
}
return NULL;
}
void stop_webserver(httpd_handle_t server)
{
if (server) {
httpd_stop(server);
}
}
void wifiAPInit(void)
{
.
. //Initialize wifi config for AP mode and start wifi
.
}
void app_main(void)
{
.
. //Initialize NVS and others...
.
httpd_handle_t server = NULL;
wifiAPinit();
server = start_webserver();
waitForUser();
stop_webserver(server);
.
. // start Wifi in STA mode and continue...
.
}
Is this principle correct?
Thanks for advice!
By far the easiest approach is to just reboot (esp_restart()) after saving new configuration.
Then select the right mode after reading the configuration on boot.
void app_main()
{
// init NVS
// load configuration from NVS
if (config.wifiSSID.empty()) {
startAPmode();
} else {
startSTAmode(config.wifiSSID, config.wifiPassword);
}
start_webserver();
// etc ...
}
You can use Both Sta and Ap at the same time
void connectSTA(char *ssid, char *pass)
{
wifi_config_t wifi_config;
memset(&wifi_config, 0, sizeof(wifi_config));
strcpy((char *)wifi_config.sta.ssid, said);
strcpy((char *)wifi_config.sta.password, pass);
esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config);
}
void connectAP()
{
wifi_config_t wifi_config =
{
.ap = {
.ssid = "my esp32",
.password = "P#ssword",
.max_connection = 4,
.authmode = WIFI_AUTH_WPA_WPA2_PSK}};
esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config);
}
void wifiInit(void *params)
{
ESP_ERROR_CHECK(nvs_flash_init());
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
nvs_handle_t nvs;
nvs_open("wifiCreds", NVS_READWRITE, &nvs);
size_t ssidLen, passLen;
char *ssid = NULL, *pass = NULL;
if (nvs_get_str(nvs, "ssid", NULL, &ssidLen) == ESP_OK)
{
if (ssidLen > 0)
{
ssid = malloc(ssidLen);
nvs_get_str(nvs, "ssid", ssid, &ssidLen);
}
}
if (nvs_get_str(nvs, "pass", NULL, &passLen) == ESP_OK)
{
if (passLen > 0)
{
pass = malloc(passLen);
nvs_get_str(nvs, "pass", pass, &passLen);
}
}
wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
connectAP();
if (ssid != NULL && pass != NULL)
{
connectSTA(ssid, pass);
}
ESP_ERROR_CHECK(esp_wifi_start());
}

UWP C++ PrintTask PreviewPage Duplication Error

I'm currently working on a print task within my app to print a couple of pages to either printer or PDF. I'm using the microsoft printsample as the basis for my code and it all works with the exception of one thing. When I change printers, the printer preview creates duplicate pages of the content I sent to the printer preview.
Here is all my code that handles the printing. Does anyone know what might be causing the print UI to create duplicate preview pages when changing between printers and or print to PDF? thanks.
void MainPage::Print_Test_Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (isPrinting) {
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
}
this->Certificate_SV_1->ScrollToVerticalOffset(0.0);
this->Certificate_SV_2->ScrollToVerticalOffset(0.0);
// CREATE THE PRINT DOCUMENT
pDocument = ref new Windows::UI::Xaml::Printing::PrintDocument();
// SAVE DOCUMENT SOURCE
pDocumentSource = pDocument->DocumentSource;
// CLEAR CACHE OF PREVIEW PAGES
printPreviewPages.clear();
// Add an event handler which creates preview pages.
pDocument->Paginate += ref new Windows::UI::Xaml::Printing::PaginateEventHandler(this, &MainPage::CreatePrintPreviewPages);
// Add an event handler which provides a specified preview page.
pDocument->GetPreviewPage += ref new Windows::UI::Xaml::Printing::GetPreviewPageEventHandler(this, &MainPage::GetPrintPreviewPage);
// Add an event handler which provides all final print pages.
pDocument->AddPages += ref new Windows::UI::Xaml::Printing::AddPagesEventHandler(this, &MainPage::AddPrintPages);
// PRINT MANAGER
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
// RAISE NEW PRINT TASK REQUEST
printTaskRequestedEventToken = printMan->PrintTaskRequested += ref new Windows::Foundation::TypedEventHandler<Windows::Graphics::Printing::PrintManager^, Windows::Graphics::Printing::PrintTaskRequestedEventArgs^>(this, &MainPage::PrintTaskRequested);
// SHOWS THE PRINTER UI
printMan->ShowPrintUIAsync();
}
.
void MainPage::CreatePrintPreviewPages(Object^ sender, Windows::UI::Xaml::Printing::PaginateEventArgs^ e)
{
Windows::UI::Xaml::Printing::PrintDocument^ printDocument = safe_cast<Windows::UI::Xaml::Printing::PrintDocument^>(sender);
hasOverFlow = false;
StackPanel^ PrinterPage = ref new StackPanel();
PrinterPage->Width = 794; PrinterPage->Height = 1123;
PrinterPage = safe_cast<StackPanel^>(this->Certificate_Page_1);
// ADD PAGE TO THE COLLECTION
printPreviewPages.push_back(PrinterPage);
PrinterPage = safe_cast<StackPanel^>(this->Certificate_Page_2);
printPreviewPages.push_back(PrinterPage);
// Report the number of preview pages created
printDocument->SetPreviewPageCount(printPreviewPages.size(), Windows::UI::Xaml::Printing::PreviewPageCountType::Final);
}
.
void MainPage::GetPrintPreviewPage(Object^ sender, Windows::UI::Xaml::Printing::GetPreviewPageEventArgs^ e)
{
Windows::UI::Xaml::Printing::PrintDocument^ localprintDocument = safe_cast<Windows::UI::Xaml::Printing::PrintDocument^>(sender);
localprintDocument->SetPreviewPage(e->PageNumber, printPreviewPages[e->PageNumber - 1]);
}
.
void MainPage::AddPrintPages(Object^ sender, Windows::UI::Xaml::Printing::AddPagesEventArgs^ e)
{
Windows::UI::Xaml::Printing::PrintDocument^ printDocument = safe_cast<Windows::UI::Xaml::Printing::PrintDocument^>(sender);
for (uint8_t i = 0; i < printPreviewPages.size(); i++) {
printDocument->AddPage(printPreviewPages[i]);
}
// Indicate that all of the print pages have been provided
printDocument->AddPagesComplete();
}
.
void MainPage::PrintTaskRequested(Windows::Graphics::Printing::PrintManager^ sender, Windows::Graphics::Printing::PrintTaskRequestedEventArgs^ e) {
Windows::Graphics::Printing::PrintTask^ printTask = e->Request->CreatePrintTask("PRINT TASK", ref new Windows::Graphics::Printing::PrintTaskSourceRequestedHandler([=](Windows::Graphics::Printing::PrintTaskSourceRequestedArgs^ args)
{
args->SetSource(pDocumentSource);
}));
// Print Task event handler is invoked when the print job is completed.
printTask->Completed += ref new Windows::Foundation::TypedEventHandler<Windows::Graphics::Printing::PrintTask^, Windows::Graphics::Printing::PrintTaskCompletedEventArgs^>([=](Windows::Graphics::Printing::PrintTask^ sender, Windows::Graphics::Printing::PrintTaskCompletedEventArgs^ e)
{
// Notify the user when the print operation fails.
if (e->Completion == Windows::Graphics::Printing::PrintTaskCompletion::Failed)
{
auto callback = ref new Windows::UI::Core::DispatchedHandler([=]()
{
this->DataStreamWindow->Text = "Printing Failed!";
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
});
Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback);
}
else if (e->Completion == Windows::Graphics::Printing::PrintTaskCompletion::Canceled)
{
auto callback = ref new Windows::UI::Core::DispatchedHandler([=]()
{
this->DataStreamWindow->Text = "Printing Cancelled!";
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
});
Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback);
}
pDocument->InvalidatePreview();
printMan = Windows::Graphics::Printing::PrintManager::GetForCurrentView();
printMan->PrintTaskRequested -= printTaskRequestedEventToken;
isPrinting = false;
});
}

Detect USB devices event

I made a console application which detects plugin and plugout events for all type of usb devices. but I wanted some filteration in it like I wanted to detect only webcams . This was done by using GUID class. The class for webcam is 'Image' class with GUID "{6bdd1fc5-810f-11d0-bec7-08002be2092f}" .The problem is that this 'Image' class is also used for scanners and I dont want to detect scanners.The code is given below:
static void Main(string[] args)
{
WqlEventQuery weqQuery = new WqlEventQuery();
weqQuery.EventClassName = "__InstanceOperationEvent";
weqQuery.WithinInterval = new TimeSpan(0, 0, 3);
weqQuery.Condition = #"TargetInstance ISA 'Win32_PnPEntity'";
ManagementEventWatcher m_mewWatcher = new ManagementEventWatcher(weqQuery);
m_mewWatcher.EventArrived += new EventArrivedEventHandler(m_mewWatcher_EventArrived);
m_mewWatcher.Start();
Console.ReadLine();
}
static void m_mewWatcher_EventArrived(object sender, EventArrivedEventArgs e)
{
bool bUSBEvent = false;
string deviceCaption = "";
string deviceType = "";
foreach (PropertyData pdData in e.NewEvent.Properties)
{
try
{
ManagementBaseObject mbo = (ManagementBaseObject)pdData.Value;
if (mbo != null)
{
foreach (PropertyData pdDataSub in mbo.Properties)
{
Console.WriteLine(pdDataSub.Name + " = " + pdDataSub.Value);
if (pdDataSub.Name == "Caption")
{
deviceCaption = pdDataSub.Value.ToString();
}
if (pdDataSub.Name == "ClassGuid" && pdDataSub.Value.ToString() == "{6bdd1fc5-810f-11d0-bec7-08002be2092f}")
{
bUSBEvent = true;
deviceType = "Image";
}
}
if (bUSBEvent)
{
if (e.NewEvent.ClassPath.ClassName == "__InstanceCreationEvent")
{
Console.WriteLine("A " + deviceType + " device " + deviceCaption + " was plugged in at " + DateTime.Now.ToString());
}
else if (e.NewEvent.ClassPath.ClassName == "__InstanceDeletionEvent")
{
Console.WriteLine("A " + deviceType + " device " + deviceCaption + " was plugged out at " + DateTime.Now.ToString());
}
}
}
}
catch (Exception ex)
{
}
}
}
for references check this link
I waited but no body answered this question so, after seeing all properties of ManagementBaseObject I found that there is a property named Service which is different for scanners. In scanners the value of Service property is usbscan while in cameras it is usbvideo.
eg.
you can do something like this
if (mbo.Properties["Service"].Value.ToString() == "usbscan")
{
//then it means it is a scanner
}
else
{
//then it means it is a camera
}
note: The main question was that how can we differentiate between a scanner and a webcam because they both use same GUID.

How to Get the list of Unsubscribed Emails from Mailchimp in C#?

Here is my code
//private void GetUnsubscribers(string apikey, string MailChimpCampaignID)
//{
// campaignUnsubscribesInput input = new campaignUnsubscribesInput();
// input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial;
// input.api_CustomErrorMessages = true;
// input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST;
// input.api_Validate = true;
// input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML;
// input.parms.apikey = apikey;
// input.parms.cid = MailChimpCampaignID;
// campaignUnsubscribes unsubscribe = new campaignUnsubscribes();
// campaignUnsubscribesOutput output = unsubscribe.Execute(input);
// Unsubscribers.AddRange(output.result.data);
// string unsubscriber = "0";
// string[] unsubs;
// foreach (listMembers list1 in output.result)
// {
// unsubscriber = list1.ToString();
// }
// string unsubscribers = Unsubscribers.Count.ToString();
// Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('Unsubscribers:: '+ ' " + unsubscribers + " ');</script>");
//}
But the problem is, i am unable to pass campaign id to this function because i am creating a new campaign every time, so each time a new id is generated for campaign.
please help, As i am new in this line, so sorry in advance if there is something wrong in the code......................

Retrieving the status of another user from libpurple (the IM library underpinning Pidgin)

I'm trying to pull the current status of another person on a SIMPLE network (Microsoft Office Communicator). I'm using libpurple, built a c++ wrapper around libpurple, and I can send/receive IMs with other users on the SIMPLE network. What I still need is to get the current status of other users
Here's my current attempt at retrieving status of another user.
Previously defined and initialized:
PurpleAccount *CommonIM::m_account -> I can send messages using this account
// the username of the person I want to get the status of, e.g.
username = "sip:blah#blah.blah.com";
//TEST instance 1
PurpleBuddy* newbody1 = purple_buddy_new(m_account, username.c_str(), NULL);
sleep(5);
PurplePresence *p1 = purple_buddy_get_presence(newbody1);
PurpleStatus *status1 = purple_presence_get_active_status(p1);
PurpleStatusType *statusType1 = purple_status_get_type(status1);
PurpleStatusPrimitive prim1 = purple_status_type_get_primitive(statusType1);
switch(prim1)
{
case PURPLE_STATUS_UNSET:
{
status = "unset";
}
break;
case PURPLE_STATUS_OFFLINE:
{
status = "offline";
}
break;
case PURPLE_STATUS_AVAILABLE:
{
status = "available";
}
break;
case PURPLE_STATUS_UNAVAILABLE:
{
status = "unavailable";
}
break;
case PURPLE_STATUS_INVISIBLE:
{
status = "invisible";
}
break;
case PURPLE_STATUS_AWAY:
{
status = "away";
}
break;
case PURPLE_STATUS_EXTENDED_AWAY:
{
status = "extended away";
}
break;
case PURPLE_STATUS_MOBILE:
{
status = "mobile";
}
break;
case PURPLE_STATUS_TUNE:
{
status = "tune";
}
break;
case PURPLE_STATUS_NUM_PRIMITIVES:
default:
{
status = "unknown";
}
break;
}
//TEST instance 1 complete
cout << _TAG << "Test instance 1: Status for " << username << " is reported as " << status << endl;
This code always returns offline as the status. It's as if purple doesn't refresh the buddy after creating a new instance, it always remains as "offline". I've dived into libpurple and pidgin to try to find this for the past few days but can't find the 'proper' way of retrieving status.
For some reason, calling this from the signed-on signal doesn't work.
Calling it from the buddy-signed-on signal works for me. Of course, in that case it will be called once for each signed-on buddy ...
sample function to be called from the "buddy-signed-on" signal:
static void buddy_signed_on(PurpleBuddy *buddy) {
GSList *buddies = purple_blist_get_buddies();
for(; buddies; buddies = buddies->next) {
PurpleBuddy *b = (PurpleBuddy *) buddies->data;
PurplePresence *presence = purple_buddy_get_presence(b);
PurpleStatus *status = purple_presence_get_active_status(presence);
printf("%s is now %s\n", b->name, purple_status_get_id(status));
}
}
Connect the signal:
purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", &handle,
PURPLE_CALLBACK(buddy_signed_on), NULL);