I am developing cocos2d-x game which have online game mode.
Online game designed and implemented by Photon Cloud SDK(http://www.exitgames.com).
I implemented only ios version but it doesn't work.
The codes that I have implemented are blow.
void NetworkLogic::opJoinRandomRoom()
{
ExitGames::Common::JVector<ExitGames::LoadBalancing::Room> roomList;
roomList = mLoadBalancingClient.getRoomList();
int count = roomList.getSize();
CCLog("Room Count = %d", count);
if(count == 0)
{
this->opCreateRoom();
}else{
mLoadBalancingClient.opJoinRandomRoom();
}
}
void NetworkLogic::update(float dt)
{
this->run();
}
void NetworkLogic::run(void)
{
if(mLastInput == INPUT_EXIT && mStateAccessor.getState() != STATE_DISCONNECTING && mStateAccessor.getState() != STATE_DISCONNECTED)
{
disconnect();
mStateAccessor.setState(STATE_DISCONNECTING);
}
else
{
State state = mStateAccessor.getState();
switch(state)
{
case STATE_INITIALIZED:
connect();
mStateAccessor.setState(STATE_CONNECTING);
break;
case STATE_CONNECTING:
break; // wait for callback
case STATE_CONNECTED:
{
ExitGames::Common::JVector<ExitGames::LoadBalancing::Room> roomList;
roomList = mLoadBalancingClient.getRoomList();
int count = roomList.getSize();
ExitGames::Common::JString tmp;
tmp = count;
EGLOG(ExitGames::Common::DebugLevel::INFO, tmp);
CCLog("Room count in Room = %d", count);
switch(mLastInput)
{
case INPUT_CREATE_GAME: // create Game
opCreateRoom();
break;
case INPUT_JOIN_RANDOM_GAME: // join Game
opJoinRandomRoom();
mStateAccessor.setState(STATE_JOINING);
break;
default: // no or illegal input -> stay waiting for legal input
break;
}
break;
}
case STATE_JOINING:
break; // wait for callback
case STATE_JOINED:
switch(mLastInput)
{
case INPUT_LEAVE_GAME: // leave Game
mLoadBalancingClient.opLeaveRoom();
mStateAccessor.setState(STATE_LEAVING);
break;
default: // no or illegal input -> stay waiting for legal input
break;
}
break;
case STATE_LEAVING:
break; // wait for callback
case STATE_LEFT:
mStateAccessor.setState(STATE_CONNECTED);
break;
case STATE_DISCONNECTING:
break; // wait for callback
default:
break;
}
}
mLastInput = INPUT_NON;
mLoadBalancingClient.service();
}
First I run one app then getRoomList function returns 0 values.
Also after first room created and run second app but it also returns getRoomList function 0.
Please help me.
I have just taken the code that you have provided in your question and copied it into the according place inside the demo of an otherwise unchanged version 3.2.2.0 build of the Photon C++ Client SDK (and removed the two CCLog() lines to make it compile without cocos2d-x) and it worked just fine for me:
The demo prints 0 for the size of the room list until I let one client create a room. Afterwards the other client prints 1.
Related
I am using text/scanner package to parse some arbitrary expressions. I am currently trying to implement a not in option, that is, if the current identifier is not, and the next is in, parse it using function notin(left, right), and otherwise we parse it as negate(right).
I've essentially got the code to manage these cases however, I am unable to rewind the scanner in case the next token is not in. I've tried by recording the position and then reassigning it later, but to no avail and haven't been able to find a different solution.
func readToken(stream *scanner.Scanner) {
switch stream.Scan() {
case scanner.Ident:
switch stream.TokenText() {
case "in":
in(left, right)
case "not":
oldPosition := stream.Position
nextToken := stream.Scan()
if nextToken == scanner.Ident {
switch stream.TokenText() {
case "in":
fmt.Println("notin")
default:
// how do we rewind the scanner?
stream.Position = oldPosition
fmt.Println("negate default")
}
} else {
fmt.Println("negate no-ident")
}
}
}
}
How can I rewind the scanner when I don't find a valid identifier?
Edit, I also tried using Peek() as below, but that still changes the state to the point that I'd need to rewind as well.
// other code
case "not":
nextIdent, err := getNextIdent(stream)
if err != nil {
fmt.Println("negate no-ident")
} else {
switch nextIdent {
case "in":
fmt.Println("notin")
default:
fmt.Println("negate default")
}
}
// other code
func getNextIdent(s *scanner.Scanner) (string, error) {
var nextIdent string
ch := s.Peek()
// skip white space
for s.Whitespace&(1<<uint(ch)) != 0 {
ch = s.Next()
}
if isIdentRune(ch, 0) {
nextIdent = string(ch)
ch = s.Next()
nextIdent += string(ch)
for i := 1; isIdentRune(ch, i); i++ {
ch = s.Next()
if s.Whitespace&(1<<uint(ch)) != 0 {
break
}
nextIdent += string(ch)
}
return nextIdent, nil
}
return "",errors.New("not a ident")
}
Note, the code I've got is a forked from Knetic/govaluate combined with a PR from GH user generikvault and some other forks. The full code can be found on my Github profile
By looking at the API references of text/scanner, I can't seem to find a way to rewind the scanner the way you want.
However, the Peek() method would get you the next rune without advancing the scanner. Inside the "not" case, you can use it to peek in advance to see if it matches.
I am trying to code my EA where if my close conditions are met, I want my EA to close all the open trades ( there are potentially more than 1 open trades ).
Here is my code for the closing trade section and when I run it through the Strategy Tester, I noticed it doesn't close my trades.
Total=0; // Amount of orders
for(int i=1; i<=OrdersTotal(); i++) // Loop through orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one
{ // Analyzing orders:
if (OrderSymbol()!=Symb)continue; // Another security
Total++; // Counter of market orders
}
}
while(true) // Loop of closing orders
{
if (OrderType()==0 && Close_Buy_Condition==true) // Order Buy is opened & Close Buy Condition is true
{
for (c=Total-1; c>=0; c--)
{
RefreshRates(); // Refresh rates
Ans=OrderClose(OrderTicket(),Lot,Bid,Slippage); // Closing Buy
}
}
if (OrderType()==1 && Close_Sell_Condition==true) // Order Sell is opened & Close Sell Condition is true
{
for (d=Total-1; d>=0; d--)
{
RefreshRates(); // Refresh rates
Ans=OrderClose(OrderTicket(),Lot,Ask,Slippage); // Closing Sell
}
}
break; // Exit while
}
I don't know where do you set value for Ask, Bid and Lot variables. But they've to change when you loop through your open positions.
You can try this function to close all positions:
bool CloseAllPositions()
{
double total;
int cnt;
while(OrdersTotal()>0)
{
// Close pending orders first, you can remove this section if you don't want pending orders to be deleted
total=OrdersTotal();
for(cnt=total-1; cnt>=0; cnt--)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
switch(OrderType())
{
case OP_BUYLIMIT :OrderDelete(OrderTicket()); break;
case OP_SELLLIMIT :OrderDelete(OrderTicket()); break;
case OP_BUYSTOP :OrderDelete(OrderTicket()); break;
case OP_SELLSTOP :OrderDelete(OrderTicket()); break;
}
}
}
// then close opened orders
total=OrdersTotal();
for(cnt=total-1; cnt>=0; cnt--)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
switch(OrderType())
{
case OP_BUY:
if (Close_Buy_Condition==true) {
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Violet);
}
break;
case OP_SELL:
if (Close_Sell_Condition==true) {
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Violet);
}
break;
}
}
}
}
return true;
}
Edit:
if you don't want to deal with pending orders at all, use this code instead of OrdersTotal():
int GetNumOpenPositions() {
int total = OrdersTotal();
double OpenBuyOrders = 0, OpenSellOrders = 0, PendBuys =0, PendSells =0;
for( i=0;i<total;i++)
{
OrderSelect(i, SELECT_BY_POS );
if ( OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
int type = OrderType();
if (type == OP_BUY ) {OpenBuyOrders=OpenBuyOrders+1;}
if (type == OP_SELL ) {OpenSellOrders=OpenSellOrders+1;}
if (type == OP_BUYSTOP ) {PendBuys=PendBuys+1;}
if (type == OP_SELLSTOP ) {PendSells=PendSells+1;}
}
}
return (OpenBuyOrders + OpenSellOrders);
}
Then total orders would be
I'm using Flash CS6 to build apps for iOS and Android.
I have built 6 working apps and in-app purchases and restoring was working properly. Now, I'm building my 7th app and I tested my in-app purchases. Purchasing works very well but when I remove the app and re-install and come to buy a product. It tells that I have already purchases the product and it will restore it for free, but it keeps loading and nothing happens.
This happened for all old apps as well.
*Note: I publish the SWF using Flash then I build the IPA using cmd
I use this as3 code:
function log(s:String):void
{
trace(s);
log_txt.text = s;
}
function initStorekit():void
{
log("initializing StoreKit..");
if (! StoreKit.isSupported())
{
log("Store Kit iOS purchases is not supported on this platform.");
return;
}
else
{
supported = true;
}
StoreKit.create();
log("StoreKit Initialized.");
// make sure that purchases will actually work on this device before continuing!
// (for example, parental controls may be preventing them.)
if (! StoreKit.storeKit.isStoreKitAvailable())
{
log("Store is disabled on this device.");
return;
}
// add listeners here
StoreKit.storeKit.addEventListener(StoreKitEvent.PRODUCT_DETAILS_LOADED,onProductsLoaded);
StoreKit.storeKit.addEventListener(StoreKitEvent.PURCHASE_SUCCEEDED,onPurchaseSuccess);
StoreKit.storeKit.addEventListener(StoreKitEvent.PURCHASE_CANCELLED,onPurchaseUserCancelled);
StoreKit.storeKit.addEventListener(StoreKitEvent.TRANSACTIONS_RESTORED, onTransactionsRestored);
// adding error events. always listen for these to avoid your program failing.;
StoreKit.storeKit.addEventListener(StoreKitErrorEvent.PRODUCT_DETAILS_FAILED,onProductDetailsFailed);
StoreKit.storeKit.addEventListener(StoreKitErrorEvent.PURCHASE_FAILED,onPurchaseFailed);
StoreKit.storeKit.addEventListener(StoreKitErrorEvent.TRANSACTION_RESTORE_FAILED, onTransactionRestoreFailed);
// initialize a sharedobject that's holding our inventory.;
initSharedObject();
var productIdList:Vector.<String>=new Vector.<String>();
productIdList.push(LEVELPACK1_ID);
productIdList.push(LEVELPACK2_ID);
productIdList.push(LEVELPACK3_ID);
productIdList.push(REMOVEADS_ID);
productIdList.push(ALLINPACKAGE_ID);
// when this is done, we'll get a PRODUCT_DETAILS_LOADED or PRODUCT_DETAILS_FAILED event and go on from there...;
log("Loading product details...");
StoreKit.storeKit.loadProductDetails(productIdList);
}
function onProductsLoaded(e:StoreKitEvent):void
{
log("products loaded.");
for each (var product:StoreKitProduct in e.validProducts)
{
trace("ID: "+product.productId);
trace("Title: "+product.title);
trace("Description: "+product.description);
trace("String Price: "+product.localizedPrice);
trace("Price: "+product.price);
}
log("Loaded "+e.validProducts.length+" Products.");
// if any of the product ids we tried to pass in were not found on the server,
// we won't be able to by them so something is wrong.
if (e.invalidProductIds.length > 0)
{
log("[ERR]: these products not valid:"+e.invalidProductIds.join(","));
return;
}
}
function onProductDetailsFailed(e:StoreKitErrorEvent):void
{
log("ERR loading products:"+e.text);
}
function initSharedObject():void
{
this.sharedObject = SharedObject.getLocal("myPurchases");
// check if the application has been loaded before. if not, create a store of our purchases in the sharedobject.
if (sharedObject.data["inventory"] == null)
{
sharedObject.data["inventory"]=new Object();
}
updateInventoryMessage();
}
/** Update Inventory Message */
function updateInventoryMessage():void
{
var inventory:Object = sharedObject.data["inventory"];
// if the value is set to something, you have it
if (inventory[LEVELPACK1_ID] != null)
{
unlockLP1_fnc();
}
if (inventory[LEVELPACK2_ID] != null)
{
unlockLP2_fnc();
}
if (inventory[LEVELPACK3_ID] != null)
{
unlockLP3_fnc();
}
if (inventory[REMOVEADS_ID] != null)
{
hideAds_fnc();
}
if (inventory[ALLINPACKAGE_ID] != null)
{
unlockLP1_fnc();unlockLP2_fnc();unlockLP3_fnc();hideAds_fnc();
}
log("Has hasUnlocked? ");
}
function purchaseUnlock(s:String):void
{
enableLoading();
// for this to work, you must have added the value of LEVELPACK_PRODUCT_ID in the iTunes Connect website
log("start purchase of non-consumable '"+s+"'...");
// we won't let you purchase it if its already in your inventory!
var inventory:Object = sharedObject.data["inventory"];
if (inventory[s] != null)
{
log("You already have unlocked this!");
return;
}
StoreKit.storeKit.purchaseProduct(s);
}
/** Example of how to restore transactions */
function restoreTransactions():void
{
enableLoading();
log("requesting transaction restore...");
StoreKit.storeKit.restoreTransactions();
}
function onPurchaseSuccess(e:StoreKitEvent):void
{
log("Successful purchase of '"+e.productId+"'");
disableLoading();
// update our sharedobject with the state of this inventory item.
// this is just an example to make the process clear. you will
// want to make your own inventory manager class to handle these
// types of things.
var inventory:Object = sharedObject.data["inventory"];
switch (e.productId)
{
case ALLINPACKAGE_ID :
inventory[ALLINPACKAGE_ID] = "purchased";
break;
case LEVELPACK1_ID :
inventory[LEVELPACK1_ID] = "purchased";
break;
case LEVELPACK2_ID :
inventory[LEVELPACK2_ID] = "purchased";
gotoAndStop("lvls");
break;
case LEVELPACK3_ID :
inventory[LEVELPACK3_ID] = "purchased";
gotoAndStop("lvls");
break;
case REMOVEADS_ID :
inventory[REMOVEADS_ID] = "purchased";
gotoAndStop("mm");
break;
default :
log("xxxxx");
// we don't do anything for unknown items.
}
// save state!
sharedObject.flush();
// update the message on screen;
updateInventoryMessage();
}
function onPurchaseFailed(e:StoreKitErrorEvent):void
{
disableLoading();
log("FAILED purchase="+e.productId+",t="+e.transactionId+",o="+e.originalTransactionId);
}
function onPurchaseUserCancelled(e:StoreKitEvent):void
{
disableLoading();
log("CANCELLED purchase="+e.productId+","+e.transactionId);
}
function onTransactionsRestored(e:StoreKitEvent):void
{
disableLoading();
log("All previous transactions restored!");
var inventory:Object = sharedObject.data["inventory"];
switch (e.productId)
{
case ALLINPACKAGE_ID :
inventory[ALLINPACKAGE_ID] = "purchased";
break;
case LEVELPACK1_ID :
inventory[LEVELPACK1_ID] = "purchased";
break;
case LEVELPACK2_ID :
inventory[LEVELPACK2_ID] = "purchased";
gotoAndStop("lvls");
break;
case LEVELPACK3_ID :
inventory[LEVELPACK3_ID] = "purchased";
gotoAndStop("lvls");
break;
case REMOVEADS_ID :
inventory[REMOVEADS_ID] = "purchased";
gotoAndStop("mm");
break;
default :
log("xxxxx");
// we don't do anything for unknown items.
}
// save state!
sharedObject.flush();
updateInventoryMessage();
}
function onTransactionRestoreFailed(e:StoreKitErrorEvent):void
{
disableLoading();
log("an error occurred in restore purchases:"+e.text);
}
My requirement is to delete all the SPListItem versions except the first 25... so I have to start deleting from 26 or index 25. One of the SPListItem in a library has so many versions... may be more than 100k that the web interface is not able to show all the versions. The size of the database is almost 900GB.
I wrote this code but I think the issue is with the item.Versions property. It tries to load all the versions in memory
foreach (SPListItem item in library.Items)
{
foundMoreVersionsThanRequired = false;
int tempVersionToKepp = howManyVersionsToKeep + 1;
for (int i = 0; i <= tempVersionToKepp; i++)
{
SPListItemVersion objVersion = null;
try
{
objVersion = item.Versions[i];
if (objVersion != null && i == tempVersionToKepp)
{
foundMoreVersionsThanRequired = true;
break;
}
}
catch
{
foundMoreVersionsThanRequired = false;
break;
}
}
if (foundMoreVersionsThanRequired)
{
int tempIndex = howManyVersionsToKeep + 1;
SPListItemVersion objVersion = null;
do
{
try
{
objVersion = item.Versions[tempIndex];
if (objVersion != null)
{
objVersion.Delete();
}
else
break;
}
catch
{
break;
}
} while (true);
}
count++;
}
I am positive that the issue is with "item.Versions" property. It seems that when you call item.Versions it loads all the objects in the memory and that is causing a lot of issues.
Any way to delete an SPListItem version directly?
why not just set the list to only keep 25 versions within SharePoint itself from the web?
I'd like my user to take a picture as an attachment by using the built in camera.
Is there someway to invoke the camera on a button press and save the resulting taken picture?
The other option is to use the BlackBerry Invoke API to start the native camera application and listen for a file system event:
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
then, later:
class FileExplorerDemoJournalListener implements FileSystemJournalListener {
public void fileJournalChanged() {
long nextUSN = FileSystemJournal.getNextUSN();
for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) {
FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
if (entry == null) {
break;
}
String path = entry.getPath();
if (path != null) {
if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){
switch (entry.getEvent()) {
case FileSystemJournalEntry.FILE_ADDED:
//either a picture was taken or a picture was added to the BlackBerry device
break;
case FileSystemJournalEntry.FILE_DELETED:
//a picture was removed from the BlackBerry device;
break;
}
}
}
}
}
}
Finally...
Application.addFileSystemJournalListener(new FileExplorerDemoJournalListener());
This will get you most of the way there... taken from: http://docs.blackberry.com/en/developers/deliverables/11942/Detect_when_img_is_added_or_removed_file_system_740288_11.jsp
http://docs.blackberry.com/en/developers/deliverables/17968/Take_a_picture_in_a_BB_device_app_1228201_11.jsp